Techniques to create portable CloudFormation (CF) Templates

1.) use a very limited number of parameters if possible and provide portable defaults if you have to use them

2.) Use Pseudo Parameters – Pseudo Parameters are built-in parameters that could formation knows about:

"Outputs" : { "MyStacksRegion" : { "Value" : { "Ref" : "AWS::Region" } }

Note the the example about “AWS::Region” is the pseudo parameter

3.) Use automatic naming where applicable – for example if you are creating a bucket in a CF Template and don’t provide a bucket name at all CF will create a random bucket name consisting of the template name, regions and a random string for the bucket name

4.) Use intrinsic functions with fn::select for examples:

The following example returns: "grapes".

JSON

{ "Fn::Select" : [ "1", [ "apples", "grapes", "oranges", "mangoes" ] ] }

Three forms of GetAZs:

{ "Fn::GetAZs" : "" }
{ "Fn::GetAZs" : { "Ref" : "AWS::Region" } }
{ "Fn::GetAZs" : "us-east-1" }

Leave a Comment

Scroll to Top