MAK
MAK

Reputation: 2283

How to execute cdk commands with contextual parameters when cdk is not installed i.e., using npm run cdk?

I have a cdk stack named Temp to which I want to pass contextual parameters.

new MyStack(app, `Temp`);

When I run the following command in bash, I get the synthesized template successfully:

cdk synth Temp -c param1=abc

However when I run the following, I am getting an error saying No stack found matching 'param1=abc'. Use "list" to print manifest

npm run cdk synth Temp -c param1=abc

Please advise how to execute cdk synth with contextual parameters when cdk is not installed?

Upvotes: 0

Views: 2061

Answers (2)

MAK
MAK

Reputation: 2283

It works by adding -- as follows:

npm run cdk synth Temp -- -c param1=abc

Thanks to https://jurosh.com/blog/npm-pass-parameters-into-script

We can use special npm command -- and pass parameters directly into all running scripts. Like this: npm start -- --server=localhost

Upvotes: 2

peter bardawil
peter bardawil

Reputation: 441

Use CfnParameter to pass an argument to your stack, check CfnParameter API link

  • First create your CfnParameter:

    const parameterName = new CfnParameter(this, "parameterName", {type:"String"});

  • Pass it to your stack:

    new MyStack(app, 'Temp', { paramPassed: parameterName.valueAsString});

  • Run cdk synth:

    cdk synth

  • Pass parameter to your stack:

    cdk deploy Temp --parameters parameterName=stackParamValue

Check this documentation provided by AWS

Upvotes: 2

Related Questions