I wrote a stack in CDK, then I'm generating the template and deploying it through
aws cloudformation deploy --template-file "$env:TEMP\template.json" --stack-name myStackName
Inside my Stack object, how can I retrieve the "myStackName" passed above to the command? I tried with .Name
and .StackName
properties but neither gave me that name.
Thanks
This is done via pseudo parameters.
import * as cdk from "@aws-cdk/core";
// in your construct...
const stack = cdk.Stack.of(this);
stack.stackName
The recommended approach is this described by alukack. But you can also do
Aws.STACK_NAME
But as described in the above link...
CloudFormation supports a number of pseudo parameters, which resolve to useful values at deployment time. CloudFormation pseudo parameters can be obtained from static members of the Aws class.
It is generally recommended to access pseudo parameters from the scope's stack instead, which guarantees the values produced are qualifying the designated stack, which is essential in cases where resources are shared cross-stack:
BTW: I experienced that the stack.stackName
returned the id of the stack which I used in CDK.. The correct Stackname used in CFN was only returned from the Aws.STACK_NAME
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With