OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Nested Stack can not be assigned a static name in aws cdk v2

  • Thread starter Thread starter Ke_Sandaru
  • Start date Start date
K

Ke_Sandaru

Guest
since there is no way to give a static name for a Nested Stack, I tried this method in Nested Stack class (before the constructor)

Code:
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)
    }

source: Source Link

Before trying this solution, it gave me nested stack name in CloudFormation as ; DevConnectBackendStack-DevConnectNestedStackDevConnectNestedStackResourceAB8916B0-IBLMSGR9L2IO

After trying above method in my nested stack I got the nested stack name as ;

Code:
DevConnectBackendStack-NestedLambdaCommonStackNestedStackNestedLambdaCommonStackNested-1X8VVCE0WRW10

But I prefer to have DevConnectBackendStack-NestedLambdaCommonStack-1X8VVCE0WRW10. why it is not possible to have this kind of a stack name ?

my-nested-stack.ts

Code:
export class NestedLambdaCommonStack extends cdk.NestedStack {

  getLogicalId(element: CfnElement): string {
        if (element.node.id.includes('NestedStackResource')) {
            return /([a-zA-Z0-9]+)\.NestedStackResource/.exec(element.node.id)![1] 
        }
        return super.getLogicalId(element)
    }
     constructor(scope: Construct, id: string, props: NestedLambdaCommonStackProps){}

}

nested stack on parent stack;

Code:
const nestedLambdaCommonStack = new NestedLambdaCommonStack(this, 'NestedLambdaCommonStack', {})
<p>since there is no way to give a static name for a Nested Stack, I tried this method in Nested Stack class (before the constructor)</p>
<pre><code>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)
}
</code></pre>
<p>source: <a href="https://github.com/aws/aws-cdk/issues/18053" rel="nofollow noreferrer">Source Link</a></p>
<p>Before trying this solution, it gave me nested stack name in CloudFormation as ;
<code>DevConnectBackendStack-DevConnectNestedStackDevConnectNestedStackResourceAB8916B0-IBLMSGR9L2IO</code></p>
<p>After trying above method in my nested stack I got the nested stack name as ;</p>
<pre><code>DevConnectBackendStack-NestedLambdaCommonStackNestedStackNestedLambdaCommonStackNested-1X8VVCE0WRW10
</code></pre>
<p>But I prefer to have <code>DevConnectBackendStack-NestedLambdaCommonStack-1X8VVCE0WRW10</code>. why it is not possible to have this kind of a stack name ?</p>
<p>my-nested-stack.ts</p>
<pre><code>export class NestedLambdaCommonStack extends cdk.NestedStack {

getLogicalId(element: CfnElement): string {
if (element.node.id.includes('NestedStackResource')) {
return /([a-zA-Z0-9]+)\.NestedStackResource/.exec(element.node.id)![1]
}
return super.getLogicalId(element)
}
constructor(scope: Construct, id: string, props: NestedLambdaCommonStackProps){}

}
</code></pre>
<p>nested stack on parent stack;</p>
<pre><code>const nestedLambdaCommonStack = new NestedLambdaCommonStack(this, 'NestedLambdaCommonStack', {})
</code></pre>
Continue reading...
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top