Cloudformation is an AWS service for configuring and managing deployment of AWS resources in a declarative, reproducible fashion. Makes it possible to create entire architectures with a single command.
Templates can be created in the following ways:
- By hand
- Using Cloudformer, which creates a template based on existing infrastructure.
- Example templates provided by AWS
Cloudformation templates are JSON files with the following 6 keys:
- Description
- Parameters
- Mappings
- Resources
- Conditions
- Outputs
Resources are the only mandatory field. Each declaration takes three parts:
- A Type, which describes the AWS resource
- Properties, unique to each resource type.
- A logical name.
Parameters can have default values which can be overidden. Useful for creating multiple types on environments, from production, to development, to testing, which minimal duplication of efforts.
The following pseudo-parameters are automagically declared:
AccountID
Region
Are... 'conditional' options. Shocking. As certain other criteria are met within the template, conditional options are triggered.
Two important functions you'll frequently make use of are:
- Fn
- Ref
It's possible to work with Cloudformation using the web interface, but that's a relatively meh experience when you could be using a terminal. Deployment will typically look something like:
aws cloudformation create-stack --stack-name startmyinstance \
--template-body file://home/ec2-user/templates/startmyinstance.json \
--parameters ParameterKey=KeyPairName,ParameterValue=MyKey ParameterKey=InstanceType,ParameterValue=t1.micro