CfnParameter giving me unresolved tokens error

0

I have this code as part of my cdk typescript

const stage = new CfnParameter(this, 'stageName');

const api = new apigateway.RestApi(this, 'typescriptapi', { description: 'example api gateway with typescript', deployOptions: { stageName: stage.valueAsString, }, .... ... **and running this command ** cdk deploy TypescriptcdkStack --parameters stageName='UAT'

it gives me error, what am I missing, I am using CDK 2.18.0 (build 75c90fa)

throw new Error(`ID components may not include unresolved tokens: ${unresolvedTokens.join(',')}`);

Error: Resolution error: ID components may not include unresolved tokens: DeploymentStage.${Token[TOKEN.200]}.

1 Answer
1

Hi there,

Values of CfnParameter cannot be resolved at synthesis, but only at deployment, so you won't be retrieving the values during the process of compiling. If you want to get the value at synthesis, you can use CDK Runtime context. Specifically, you can set the values of context via:

  • Through the --context option to the cdk command. (These values are always strings.)

  • In the project's cdk.context.json file.

  • In the context key of the project's cdk.json file.

  • In the context key of your ~/.cdk.json file.

  • In your AWS CDK app using the construct.node.setContext() method.

Then, you can get a context value using the construct.node.tryGetContext method.

SUPPORT ENGINEER
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.

Guidelines for Answering Questions