Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS::Route53RecoveryControl::Cluster - [BUG] - There is no way to access clusterEndpoints return value. #2029

Open
tmokmss opened this issue Apr 27, 2024 · 0 comments

Comments

@tmokmss
Copy link

tmokmss commented Apr 27, 2024

Name of the resource

AWS::Route53RecoveryControl::Cluster

Resource Name

No response

Issue Description

Hi, AWS::Route53RecoveryControl::Cluster returns a value called ClusterEndpoints, which is an array of objects ClusterEndpoint.

So how can we reference each value of the array, e.g. the endpoint of the first element? As far as I read the document, there is no way to handle an array of objects with GetAtt intrinsic function.

Usecase: I want to pass the endpoint of the cluster to Lambda environment variable.

Expected Behavior

We can access clusterEndpoints return value just like other string return values.

Observed Behavior

We cannot access clusterEndpoints return value.

Test Cases

Template to test (Note that ARC can only be deployed in us-east-1 region):

{
 "Resources": {
  "Cluster": {
   "Type": "AWS::Route53RecoveryControl::Cluster",
   "Properties": {
    "Name": "ARC-test"
   }
  }
 },
 // THE BELOW IS INVALID
 "Outputs": {
  "Exportaa": {
   "Value": {
    "Fn::Select": [
     0,
     {
      "Fn::GetAtt": [
       "Cluster",
       "ClusterEndpoints"  // How can we reference the endpoint?
      ]
     }
    ]
   },
   "Export": {
    "Name": "aa"
   }
  }
 }
}

Other Details

Workaround: use custom resource to get these values. CDK Example:

    const cfnCluster = new route53recoverycontrol.CfnCluster(this, 'Cluster', {
      name: 'ARC-Test',
    });

    const handler = new Function(this, 'DescribeClusterHandler', {
      runtime: Runtime.NODEJS_20_X,
      handler: 'index.handler',
      timeout: cdk.Duration.seconds(30),
      code: Code.fromInline(`
const response = require('cfn-response');
const sdk = require('@aws-sdk/client-route53-recovery-control-config');
// Route53RecoveryControlConfig API is only available on us-west-2
const client = new sdk.Route53RecoveryControlConfigClient({region: 'us-west-2'});

exports.handler = async function(event, context) {
  try {
    console.log(event);
    if (event.RequestType == 'Delete') {
      return await response.send(event, context, response.SUCCESS);
    }
    const clusterArn = event.ResourceProperties.ClusterArn;
    // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/route53-recovery-control-config/command/DescribeClusterCommand/
    const command = new sdk.DescribeClusterCommand({ClusterArn: clusterArn});
    const res = await client.send(command);
    const clusterEndpoints = res.Cluster.ClusterEndpoints;
    const endpoints = clusterEndpoints.map(c=>c.Endpoint).join(',');
    const regions = clusterEndpoints.map(c=>c.Region).join(',');
    await response.send(event, context, response.SUCCESS, {endpoints, regions}, clusterArn);
  } catch (e) {
    console.log(e);
    await response.send(event, context, response.FAILED);
  }
};
`),
    });
    handler.addToRolePolicy(
      new PolicyStatement({
        actions: ['route53-recovery-control-config:DescribeCluster'],
        resources: [cfnCluster.attrClusterArn],
      }),
    );

    const describeClusterResult = new cdk.CustomResource(this, 'DescribeClusterResult', {
      serviceToken: handler.functionArn,
      resourceType: 'Custom::DescribeClusterResult',
      properties: { ClusterArn: cfnCluster.attrClusterArn },
    });

    const clusterEndpoints = describeClusterResult.getAttString('endpoints');
    const clusterEndpointRegions = describeClusterResult.getAttString('regions');
@tmokmss tmokmss added the bug label Apr 27, 2024
@cfn-github-issues-bot cfn-github-issues-bot added this to Researching in coverage-roadmap Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
coverage-roadmap
  
Researching
Development

No branches or pull requests

1 participant