Stack names are not honoured when creating a nested stack
See original GitHub issueStack names are not honoured when creating a multi-stack, multi-environment CDK application
Reproduction Steps
I am trying to create a CDK app with multiple stacks that is deployed to multiple environments, e.g.
#!/usr/bin/env node
import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
import * as lambda from '@aws-cdk/aws-lambda';
class PersistenceStack extends cdk.Stack {
public readonly bucket: s3.Bucket;
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
this.bucket = new s3.Bucket(this, 'bucket');
}
}
interface ApplicationStackProps extends cdk.StackProps {
bucket: s3.Bucket;
}
class ApplicationStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: ApplicationStackProps) {
super(scope, id, props);
const myLambda = new lambda.Function(this, 'my-lambda', {
runtime: lambda.Runtime.NODEJS_12_X,
code: new lambda.AssetCode('my-lambda'),
handler: 'index.handler'
});
props.bucket.grantReadWrite(myLambda);
}
}
class MyApp extends cdk.Construct {
constructor(scope: cdk.Construct, id: string, props: cdk.StackProps) {
super(scope, id);
const persistenceStack = new PersistenceStack(this, 'persistence-stack', {
...props,
description: 'persistence stack',
stackName: `${id}-persistence-stack`,
});
const applicationStack = new ApplicationStack(this, 'application-stack', {
...props,
description: 'application stack',
stackName: `${id}-application-stack`,
bucket: persistenceStack.bucket,
});
applicationStack.addDependency(persistenceStack);
}
}
const app = new cdk.App();
new MyApp(app, `test`, { env: { account: '111111111111', region: 'eu-west-1' } });
new MyApp(app, `prod`, { env: { account: '222222222222', region: 'eu-west-1' } });
Expected result
I expected to see “nice” (or at least predictable) stack names when executing $ npx cdk synth
since I have specified the stackName
properties when calling the constructors, e.g.
Successfully synthesized to [...]/my-app/cdk.out
Supply a stack id (prodpersistencestack, testpersistencestack, prodapplicationstack, testapplicationstack) to display its template.
Actual result
Stack names ends with random / hashed characters similar to:
Successfully synthesized to [...]/my-app/cdk.out
Supply a stack id (prodpersistencestackFE36DF49, testpersistencestack6C35C777, prodapplicationstackA0A96586, testapplicationstackE19450AB) to display its template.
Motivation
I need “nice” (or at least predictable) stack names to feed into the next step our CI/CD pipeline so that I can configure the build server to deploy the CDK app, e.g.
npx cdk deploy \
--app cdk.out \
--require-approval never \
testpersistencestack
npx cdk deploy \
--app cdk.out \
--require-approval never \
testapplicationstack
Environment
- CLI Version: 1.21.1 (build 842cc5f)
- Framework Version: 1.21.1
- OS: macOS Catalina Version 10.15.2
- Language: TypeScript
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Working with nested stacks - AWS CloudFormation
Nested stacks are stacks created as part of other stacks. You create a nested stack within another stack by using the AWS::CloudFormation::Stack resource....
Read more >Cloudformation stack with nested resources fails to create
The first environment to use the nested stack's resources creates ok, but the second one fails when trying to run the nested stack....
Read more >How to use AWS CloudFormation with nested stacks - YouTube
Watch this step-by-step tutorial to learn how to use AWS CloudFormation with nested stacks. Nested stacks are stacks created as part of ...
Read more >CloudFormation's nested stack - Awstut
The creation of the root stack is also performed using the AWS CLI. $ aws cloudformation create-stack \ --stack-name fa-013 \ --template ......
Read more >Working with AWS CloudFormation - Part 2
Nested stacks allow you to build templates that can be reused to build ... aws cloudformation create-change-set --stack-name todobackend ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is straight-up bullshit that you can not simply force “normal” ids in your cdk application. Bad design choice.
Technically, it’s horsesht, not bulls#t. Bullsh#$ would imply it’s a lie.