CloudFormation

Infrastructure as Code on AWS

Essentials

  • Pure definition of Infrastructure as Code:

    • You can "convert" you application's architecture into a JSON or YAML formatted template (architecture is literally code)

    • You can then use that JSON/YAML to deploy out updated or replicated copies of that architecture to multiple regions

  • Can be built off JSON/YAML templates, either fed in or built in a WYSIWYG tool called the Cloudformation Designer

  • Also has many templates with wizards for popular deployments like WordPress or LAMP stack

Benefits

  • Saves time - You don't have to manually duplicate architectures

  • Version control your infrastructure, allowing for rollbacks to previous versions.

  • Backups of infrastructure

  • Disaster recovery

CloudFormation Engine

  • Create Stack

  • Update Stack - Change Sets

    • Has a "diff-ing" tool that allows you to approve suggested changes

    • Templates stack, smaller templates can live in one big template.

  • Delete Stack

  • Nested Stacks

Template

  • Resources

    • Services to deploy, attributes

    • EC2, VPC, Subnet, Security Groups...

    • User Data Script

    • Custom Resources

  • Parameters

    • Variables in template

    • User prompted for values at run time

    • Key Pair, Instance Type, DB Password, etc.

  • Mappings

    • Lookup Table

    • AMIs by Region

  • Conditions

    • Define if a resource will be created

    • Environment = PROD

  • Outputs

    • Information to Return about Stack

    • ELB DNS Name

Help Scripts

  • cfn-init (CloudFormation Init)

    • packages

    • users, groups

    • files

    • commands, services

  • cfn-signal

    • user with wait conditions and creation policies

    • Signals that will be sent back to CloudFormation

  • cfn-hup

    • in place instance update of packages and software

    • changes to metadata

Last updated

Was this helpful?