RandomUser
RandomUser

Reputation: 4220

Is it possible to statically specify AWS::StackName inside a cloudformation template?

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:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html#cfn-pseudo-param-stackname

Upvotes: 16

Views: 11086

Answers (4)

Tony
Tony

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

VenVig
VenVig

Reputation: 915

Specify that in the samconfig.toml as

[dev]
[dev.deploy]
[dev.deploy.parameters]
stack_name = "MyStackName"

Upvotes: 0

Warren Kim
Warren Kim

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

Rafał Wrzeszcz
Rafał Wrzeszcz

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

Related Questions