Skip to content

Instantly share code, notes, and snippets.

@jqtrde
Last active August 29, 2015 14: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 jqtrde/ca898e46df62e72b8883 to your computer and use it in GitHub Desktop.
Save jqtrde/ca898e46df62e72b8883 to your computer and use it in GitHub Desktop.
On using Cloudformation

On using Cloudformation

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:

  1. By hand
  2. Using Cloudformer, which creates a template based on existing infrastructure.
  3. Example templates provided by AWS

Cloudformation templates are JSON files with the following 6 keys:

  1. Description
  2. Parameters
  3. Mappings
  4. Resources
  5. Conditions
  6. Outputs

Templates

Resources

Resources are the only mandatory field. Each declaration takes three parts:

  1. A Type, which describes the AWS resource
  2. Properties, unique to each resource type.
  3. A logical name.

Parameters

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

Conditions

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

Methods

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment