Skip to content

Instantly share code, notes, and snippets.

@kevinhooke
Created February 23, 2021 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinhooke/7108aba972b21138b3db3f9a896f1228 to your computer and use it in GitHub Desktop.
Save kevinhooke/7108aba972b21138b3db3f9a896f1228 to your computer and use it in GitHub Desktop.
AWS CloudFormation templates
Resources
- this section is the only required section in template
- you can define 1 to max 200 resources
AWSTemplateFormatVersion is optional
Parameters
- optional
- up to 60 per template
- Default - specify a default value if not passed
- AllowedValues - specify a range of valid values
Type: String, Number, List<Number>, CommaDelimitedList e.g. "a, b, c"
AWS resource types, validate based on resources in your account e.g.
AWS::EC2::Instance::Id
AWS::EC2::VPC::Id
AWS::EC2::Subnet::Id
AWS::EC2::SecurityGroup::Id
AWS::EC2::Volume::Id
... CloudFormation in Console will show these as a list of valid values in your account
You can also specify these as a List
List<AWS::EC2::Subnet::Id>
Constraints
- ConstraintDescription
- AllowedPattern - regex for valid value
- AllowedValues
- MaxLength / MinLength - for Strings
- MaxValue / MinValue - for Numbers
- NoEcho : will mask value in describe stack and in AWS onsole
Mappings: look up maps for values
Mappings:
MapName:
us-west-1:
dev: ami-123
prod: ami-456
us-west-2:
dev: ami-111
prod: ami-222
This is used with a !FindInMap [MapName, !Ref RegionName, !Ref env]
- if RegionName=us-west-1 and env=dev, returned ami value = ami-123
Conditions - set a boolean value based on a condition
Conditions:
isProd: !Equals: [!Ref EvnName, prod]
used with an !If [isProd]
Metadata section can be arbritary metadata about the template, but also uses some key property names,
for example AWS::CloudFormation::Init to define EC2 init configs:
Metadata:
AWS::CloudFormation::Init:
AWS:CloudFormation::Interface
- allows you to configure ParameterGroups and ParameterLables to control how CloudFormation diplays in Console
Outputs:
- key value pairs that are created on completion of stack creation
- max 60 per stack
- allows sharing of stack resources across stacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment