Is there a way to ensure that when running npx cdk synth
in an AWS CDK application consisting of multiple stacks intended for deployment in various environments, the stack names are displayed in a more user-friendly manner?
#!/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' } });
The issue I encountered is that it generates outputs like:
Successfully synthesized to [...]/my-app/cdk.out
Supply a stack id (prodpersistencestackFE36DF49, testpersistencestack6C35C777, prodapplicationstackA0A96586, testapplicationstackE19450AB) to display its template.
My expectation was to have "nice" stack names (as I specified the stackName
properties during the constructors):
Successfully synthesized to [...]/my-app/cdk.out
Supply a stack id (prodpersistencestack, testpersistencestack, prodapplicationstack, testapplicationstack) to display its template.
Motivation: I require "nice" (or at least consistent) stack names for our CI/CD pipeline to seamlessly deploy the CDK app.
AWS CDK version: 1.21.1