Infrastructure as Code with AWS CloudFormation and Sceptre

Infrastructure as Code with AWS CloudFormation and Sceptre

A high-level introduction to two of my favourite AWS automation tools: CloudFormation and Sceptre

Bde491c958e31e00a79ef0ce8d8aeb44?s=128

Kristian Glass

July 09, 2017
Tweet

Transcript

  1. Infrastructure as Code with AWS CloudFormation and Sceptre Kristian Glass

    - 2017/07 Kristian Glass / @doismellburning 1
  2. Why Infrastructure as Code? We want the same things from

    our infrastructure as from our code: • Version controlled • Tested • Reproducible • Documented Kristian Glass / @doismellburning 2
  3. CloudFormation • YAML (or JSON...) templates • Define AWS Resources

    • Configuration Parameters • Optional Outputs for further use Kristian Glass / @doismellburning 3
  4. CloudFormation Basic Example Template Resources: "WebsiteBucket": Type: "AWS::S3::Bucket" Properties: AccessControl:

    "PublicRead" WebsiteConfiguration: IndexDocument: "index.html" ErrorDocument: "error.html" Kristian Glass / @doismellburning 4
  5. CloudFormation Basic Example Usage $ aws cloudformation create-stack \ --stack-name

    mystack \ --template-body file://template.yaml \ --parameters \ ParameterKey=Key1,ParameterValue=Value1 \ ParameterKey=Key2,ParameterValue=Value2 \ # etc. This is not fun Kristian Glass / @doismellburning 5
  6. So? Use a wrapper! • Everyone realises they want a

    CloudFormation wrapper quickly • Dozens to choose from! Kristian Glass / @doismellburning 6
  7. Sceptre! https://sceptre.cloudreach.com/ Convenient and unintrusive AWS wrapper • Write CloudFormation

    templates as normal • Add a small bit of directory structure • Add some YAML configuration files Kristian Glass / @doismellburning 7
  8. Sceptre Example Directory Structure $ tree . !"" config #

    !"" config.yaml # !"" live # # $"" www.yaml # $"" www.yaml $"" templates $"" www.yaml Kristian Glass / @doismellburning 8
  9. Sceptre Example Configuration $ cat config/config.yaml # General "project" config

    region: us-east-1 project_code: www # Naming prefix for grouping Kristian Glass / @doismellburning 9
  10. Sceptre Example Configuration $ cat config/www.yaml # Configuration for the

    www stack template_name: templates/www.yaml Kristian Glass / @doismellburning 10
  11. Sceptre Example Configuration $ cat config/live/www.yaml # Configuration for the

    www stack in the live environment parameters: DomainName: www.example.com Kristian Glass / @doismellburning 11
  12. Sceptre Example Usage $ sceptre launch-env live # Launches/updates all

    stacks in the live environment sceptre.stack - live/www - Launching stack sceptre.stack - live/www - Stack is in the UPDATE_COMPLETE state sceptre.stack - live/www - Updating stack sceptre.stack - live/www - No updates to perform. Kristian Glass / @doismellburning 12
  13. CircleCI Example Configuration $ cat circle.yml test: override: - sceptre

    validate-template live www deployment: live: branch: - master commands: - sceptre launch-env live - sceptre describe-stack-outputs live www Kristian Glass / @doismellburning 13
  14. Sceptre - What else? • Manage CloudFormation Change Sets •

    Connect Stacks together • Source Parameters from external files, environment variables and more • Configure hooks to run when Sceptre actions occur Kristian Glass / @doismellburning 14
  15. Questions? mail@doismellburning.co.uk Kristian Glass / @doismellburning 15