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.

(core): Nested Stacks have a crazy logical ID

See original GitHub issue

What is the problem?

Recently, we found out the construct id of the nested stack occurred twice in its logical id.

For example:

##### Parent infra stack ##### 
this.fdLifecycleCommonLambdas = new MyNestedStackConstruct(this, "MyNestedStackConstruct", {
 ...
 });
 
 
#### Nested stack #####
export class MyNestedStackConstruct extends NestedStack {
    ...
    constructor(parent: Construct, name: string, props: FdLifecycleCommonLambdasProps) {
        super(parent, name);
    }
    ...
}
#### Generated template ####
...
"Resources": {
    "MyNestedStackConstructNestedStackMyNestedStackConstructNestedStackResource3E193B32": {
            ^^^^^^^^^^^ oh no                                   ^^^^^^^^^^^^^^^^^^^^^^^
      "Type": "AWS::CloudFormation::Stack",
      "Properties": {}
    ...
}

Caused by the code here:

https://github.com/aws/aws-cdk/blob/2b6c2dadc039f7c4255f6864386ba1dd28b6fc4f/packages/%40aws-cdk/core/lib/nested-stack.ts#L123-L133

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
konstantinjcommented, Oct 10, 2022

re-posting my temporary solution for this here:

    getLogicalId(element: CfnElement): string {
        if (element.node.id.includes('NestedStackResource')) {
            return /([a-zA-Z0-9]+)\.NestedStackResource/.exec(element.node.id)![1] // will be the exact id of the stack
        }
        return super.getLogicalId(element)
    }

Place this inside your nested stacks to get a normal name like: ParentStackName-NestedStackName-LWJUNJMGDHO7

2reactions
RobReuscommented, Apr 25, 2022

Is there anything happening on this issue? The crazy long names is bad as it is, but when doing a cross stack parameter reference between 2 nested stacks, the resulting parameter name is even crazier. Its currently not breaking anything for me, but I can’t imagine this naming behavior is intended.

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 >
A better way to structure AWS CDK projects around Nested ...
The idea is to use fewer stacks but without changing the logic (just the minimum necessary)!. Resources in the AWS CDK. Every time...
Read more >
CloudFormation - Access Output of Parent Stack in Child ...
It seems you have two logical ID with the same name "LambdaTest", one in resource section and other in output section.
Read more >
CDK tips, part 3 – how to unblock cross-stack references
Of course, this implies that the Stack with the export has to be deployed ... and the logical ID of the Output itself...
Read more >
serverless-plugin-nested-stacks
Serverless AWS Nested Stacks. Yet another AWS nested stack plugin! ... (Required) The logical ID of the nested stack resource.
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