How to change StackName when using CDK Deploy
We can pass stackName as a property, if it's not passed, then it uses Id HelloCdkStack
as stack name.
We can pass something like process.env.STACK_NAME
to stackName and override it from command line
const app = new cdk.App();
const env = { account: CRM, region: AWS_REGION };
new HelloCdkStack(app, "HelloCdkStack", {
env,
stackName: process.env.STACK_NAME,
});
Then
export STACK_NAME=MyStack1;cdk deploy
OR
export STACK_NAME=MyStack2;cdk deploy --stackName MyStack2
I did it with context
//Get data from Conext
const stackName = app.node.tryGetContext('stackName')
new TestCdkProjectStack(app, 'TestCdkProjectStack', {stackName: stackName});
Run the CDK deploy with --context option:
cdk deploy --context stackName=YourStack
You can also add your context data in cdk.json file