question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stack names are not honoured when creating a nested stack

See original GitHub issue

Stack 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:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

33reactions
laimonassutkuscommented, Aug 13, 2020

This is straight-up bullshit that you can not simply force “normal” ids in your cdk application. Bad design choice.

6reactions
ekeysercommented, Dec 31, 2021

Technically, it’s horsesht, not bulls#t. Bullsh#$ would imply it’s a lie.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found