Rome_Leader
Rome_Leader

Reputation: 2700

Parameterizing Resource Names in CloudFormation Template?

This answer here: Is there a way to parameterize cloud formation resource names? didn't really help as I am looking to set the physical name, not the logical one. I was hoping for something along the lines of setting a parameter in the parameters list like:

"ELBName": {
  "Type": "String",
  "Default": "xxx",
  "Description": "The Production Number for this stack (e.g. xxx)"
}

and then

"LoadBalancerName": "prod" + {Ref: "ELBName"}

although that concatenation directly is not possible. Is there any way to do what I want? My end goal is to take a template I've created and use it to create many copies of itself, each with the same resources, but different names, possibly through a nested stack.

Upvotes: 3

Views: 5142

Answers (1)

Manish Joshi
Manish Joshi

Reputation: 3760

Use Fn::Join function to do this:

            "LoadBalancerName":{
           "Fn::Join":[
              "",
              [
                 "prod",
                 {
                    "Ref":"ELBName"
                 }
              ]
           ]
        }

This will give the name as prod01 assuming ELBName parameter has been passed the value 01

Upvotes: 2

Related Questions