Reputation: 4220
Is it possible to statically specify AWS::StackName inside a cloudformation template? Or can this only be specified as a parameter when you run the template?
As far as I understand, this value can only be read via pseudo parameters, not set:
Upvotes: 16
Views: 11086
Reputation: 21
Old..but if anyone is still looking for an answer:
You can specify the stack name inside cloudformation by using the intrinsic function Fn::Sub :
!Sub ${AWS::StackName}
ref: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html
Upvotes: 1
Reputation: 915
Specify that in the samconfig.toml as
[dev]
[dev.deploy]
[dev.deploy.parameters]
stack_name = "MyStackName"
Upvotes: 0
Reputation: 306
A less than ideal but usable workaround if your goal is just to standardize stack name on manual AWS Console deployments can be to add a "fake" Parameter that a user can copy and paste.
...
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Stack Name Config"
Parameters:
- StacknameToCopy
ParameterLabels:
StacknameToCopy:
default: Stack Name to Copy
Parameters:
StacknameToCopy:
Type: String
Description: Copy and paste this stack name above when deploying
Default: SPECIFIC-naming-convention-123
Programmatic option would require using a framework like serverless.com or an AWS SDK/CLI wrapper.
Upvotes: 2
Reputation: 2067
No, you can't.
Template is just a content of your stack, it doesn't set it's metainfo (like name, deployment region etc.).
Note, that you can use same template for multiple stacks, or even sub-stacks.
Upvotes: 15