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 回答
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.

支持工程师
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则