Skip to content

Using aws sdk alongside Cloud-formation to fetch resources.

0

Hello, I'm trying to create connect instance and the resources within it using Cfn templates. for this -- I'm creating two stacks within the same CDK app. In the first stack I'm just creating a connect instance and exporting its ARN (from the template.) In the second stack, Im importing this instance ARN and creating other resources like queues,users,etc for this instance... In my 2nd stack I have to use aws sdk client to call connect apis, ex- listQueues. (these api's accepts instance arn in their request). But while building the app I'm getting an error from sdk client - "Invalid parameter: ${Token[TOKEN.657]}". Is there a way I can get instance ARN string from cloud-formation in my second stack for this use case?

asked 2 years ago284 views
2 Answers
0

The error occurs because the AWS SDK client is receiving an unresolved CloudFormation token (${Token[TOKEN.657]}) instead of the actual ARN. To resolve this, ensure the instance ARN is fully resolved before passing it to the SDK client, possibly by using CloudFormation outputs or environment variables to store and reference the resolved ARN.

EXPERT
answered 2 years ago
  • Actually I'm creating both the stacks in one app. I'm getting this error while I build the APP. Is it possible to get the actual ARN (in the first stack) at the build time?

  • To resolve the issue, you need to create cross-stack references. The error occurs because the ARN from the first stack isn't resolved at build time. To fix this, use CfnOutput in the first stack and reference it in the second stack using Fn.importValue. This ensures the ARN is resolved before being passed to the AWS SDK client.

    Check these resources:

    😔 Also, you flagged my answer, but I'm only trying to help without expecting anything in return. This could cause problems or even lead to my account being banned without any valid reason.

  • Thank you, Sorry for flagging the answer, I was not aware of the possible consequences. I thought its to marking the answer as incomplete/not-relevant.

0

This happens because when you synthesize your app, not all values such as ARNs are available to be resolved. Resources need to be created before their ARNs are available. CDK uses tokens to represent these and these typically get resolved to Cloudformation Ref intrinsic functions. More information on tokens can be found in the CDK documentation page on tokens [1]. As the previous answer mentions, the recommended way to pass values from one stack to another within the same application is to either use a cross-stack reference or to use Parameter Store. More information and code samples can be found in this article [2]. Cross-stack references are done by exporting a variable containing the necessary value in one stack class and passing it in via the properties to another. CDK automatically handles transforming these to the relevant CloudFormation outputs.

[1] https://docs.aws.amazon.com/cdk/v2/guide/tokens.html

[2] https://repost.aws/knowledge-center/cdk-cross-stack-reference

AWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.