Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

Kristian Glass

July 09, 2017
Tweet

More Decks by Kristian Glass

Other Decks in Technology

Transcript

  1. Infrastructure as Code with AWS
    CloudFormation and Sceptre
    Kristian Glass - 2017/07
    Kristian Glass / @doismellburning 1

    View full-size slide

  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

    View full-size slide

  3. CloudFormation
    • YAML (or JSON...) templates
    • Define AWS
    Resources
    • Configuration
    Parameters
    • Optional
    Outputs
    for further use
    Kristian Glass / @doismellburning 3

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  6. So? Use a wrapper!
    • Everyone realises they want a CloudFormation wrapper quickly
    • Dozens to choose from!
    Kristian Glass / @doismellburning 6

    View full-size slide

  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

    View full-size slide

  8. Sceptre Example Directory Structure
    $ tree
    .
    !"" config
    # !"" config.yaml
    # !"" live
    # # $"" www.yaml
    # $"" www.yaml
    $"" templates
    $"" www.yaml
    Kristian Glass / @doismellburning 8

    View full-size slide

  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

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  15. Questions?
    [email protected]
    Kristian Glass / @doismellburning 15

    View full-size slide