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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南