Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

60
© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc. Zero to Sixty: AWS CloudFormation Chetan Dandekar, Senior Product Manager – AWS CloudFormation Capen Brinkley, Software Developer – Intuit November 13, 2013

description

"AWS CloudFormation gives developers and systems administrators an easy way to create and manage a collection of related AWS resources, provisioning and updating them in an orderly and predictable fashion. In this Zero to Sixty session, learn about CloudFormation's latest features along with best practices for using them, including maintaining complex environments with CloudFormation, template management and re-use, and controlling stack updates. Demos and code samples are available to all session attendees. Are you new to AWS CloudFormation? Get up to speed for this session by first completing the 60-minute Fundamentals of CloudFormation lab in the Self Paced Lab Lounge."

Transcript of Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Page 1: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

© 2013 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified, or distributed in whole or in part without the express consent of Amazon.com, Inc.

Zero to Sixty: AWS CloudFormation Chetan Dandekar, Senior Product Manager – AWS CloudFormation Capen Brinkley, Software Developer – Intuit November 13, 2013

Page 2: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

AWS CloudFormation

creation order? how long do I pause? what errors can I recover from?

Instruction Manual

Instruction Manual

Instruction Manual

Provisioning Script(s)

what environment config and utilities does my script depend on?

can my script be faster? will this script work again?

Model Click Done

Page 3: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

AWS CloudFormation

Dev

Test

Staging

Prod

Demos

Regions

Version Control Replicate

Standardization

Service Catalog

Page 4: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

AWS CloudFormation Automate

CloudFormation

Build Pipeline

Config

Template Snippets

Code

API

API

SNS

Monitor Progress

Page 5: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Intuit’s CloudFormation Story

Page 6: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Key Takeaways

• How we use CloudFormation to manage large scale applications

• Methodologies and tools you can use to follow a similar path

Page 7: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Infrastructure Design

Template Management

Stack Management

Bootstrapping

Page 8: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013
Page 9: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Live Community Traffic April 15

Feb. 1

Page 10: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Amazon EC2 Amazon S3

Amazon RDS Elastic Load Balancing

Page 11: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Infrastructure as Code

Page 12: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Auto Scaling Group

Web App

Server

App Tier

Web App

Server

Page 13: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013
Page 14: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Amazon Route 53

Amazon EC2

Amazon S3

Amazon RDS

Amazon ElastiCache

Amazon CloudFront

Amazon CloudWatch

AWS CloudFormation

AWS IAM

Amazon SQS

Amazon SES Amazon SNS

Service Oriented Architecture

Page 15: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

SQS Queue App Tier

Auto Scaling Group

Web App

Server

Web App

Server

Multiple Templates, Loosely Coupled

Page 16: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Multiple Templates, Loosely Coupled

Easy To Reason About

Reusable

Page 17: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Stack Management

Page 18: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Simple Deploy https://github.com/intuit/simple_deploy

Page 19: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

attributes clone create deploy destroy environments events execute instances

list outputs parameters protect resources status template update

Simple Deploy Commands attributes clone create deploy destroy environments events execute instances

list outputs parameters protect resources status template update

Page 20: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

elb-1

Auto Scaling Group

app-1 (v1.0.0) Blue

Auto Scaling Group

app-2 (v1.1.0) Green

Page 21: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

$ simple_deploy environments

Default

lc_preprod_us_west_1

lc_preprod_us_west_2

lc_preprod_us_east_1

PROD_lc_prod_us_west_1_PROD

PROD_lc_prod_us_west_2_PROD

PROD_lc_prod_us_east_1_PROD

Page 22: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

$ simple_deploy list \

–-environment lc_preprod_us_west_1

lc-dev-elb-1

lc-dev-app-1

lc-dev-db-master-1

lc-dev-db-parameter-group

Page 23: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

simple_deploy create \

–-environment lc_preprod_us_west_1 \

–-name lc-dev-app-2 \

–-template app.json \

–-input-stack lc-dev-elb-1 \

–-input-stack lc-dev-db-master-1 \

–-attribute chef_repo=3f57f9f \

–-attribute app=bcb68de

Page 24: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

simple_deploy clone

--environment lc_preprod_us_west_1 \

--source-stack lc-dev-1-app-1 \

--name lc-dev-1-app-2 \

--attribute app=afdac509b \

--attribute chef_repo=a4531e5ff6

Page 25: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

simple_deploy destroy

--environment lc_preprod_us_west_1 \

--name lc-dev-1-app-1

Page 26: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Code / CI / Artifact

Simple Deploy

CloudFormation

Autoscaling

Userdata

CloudFormation::Init

Chef

Bootstrapping

Page 27: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

> GET http://169.254.169.254/latest/user-data

#!/bin/bash

yum update -y aws-cfn-bootstrap

/opt/aws/bin/cfn-init –-stack lc-app-stack

-–verbose --resource InstanceLaunchConfig

--region=us-west-2 –-configsets bootstrap

"UserData": { "Fn::Base64": { "Fn::Join": ["", [

"#!/bin/bash\n",

"yum update -y aws-cfn-bootstrap\n",

"/opt/aws/bin/cfn-init --stack “,

{ "Ref": "AWS::StackName" },

" --verbose"

" --resource InstanceLaunchConfig",

" --region=", { "Ref": "AWS::Region" },

" -configsets bootstrap", "\n”

CloudFormation Instance User Data

Page 28: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Configsets Commands

Files Groups

Packages Services Sources Users

CloudFormation::Init Resources

Configsets Commands

Files Groups

Packages Services Sources Users

Page 29: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

"configSets”: {

"bootstrap”: [ "create_files",

"install_packages",

"run_chef",

"clean_up” ]

}

Page 30: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

"create_files": {

"files": {

"/etc/chef/ohai/hints/ec2.json": {

"content": "{}",

"mode": "000400",

"owner": "root",

"group": "root"

}

}

}

Page 31: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

"install_packages": {

"packages": {

"yum”: {

"chef”: [ "11.6.2-1" ]

}

}

}

Page 32: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

"run_chef": {

"commands": {

"1_download_chef_repo": { ... },

"2_decrypt_chef_repo": { ... },

"3_extract_chef_repo": { ... },

"4_run_chef": { ... }

}

}

"run_chef": {

"commands": {

"1_download_chef_repo": { ... },

"2_decrypt_chef_repo": { ... },

"3_extract_chef_repo": { ... },

"4_run_chef": { ... }

}

}

Page 33: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

"run_chef": {

"commands": {

"run_chef": {

"command": "/usr/bin/chef-solo \

–c /var/chef/config/solo.rb \

–o ", { "Ref", "Role" }

}

}

}

Page 34: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

"clean_up" : {

"commands": {

"1_cleanup_files" : {

"command": "rm –rf /var/tmp/chef_repo.tar.gz \

/var/tmp/chef_repo.tar.gz.gpg"

}

}

}

Page 35: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

The Climb

Page 36: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

What’s New in AWS CloudFormation

Page 37: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Let’s take an example

Scalable Reliable Highly Available

Page 38: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Two Types of Tasks

Develop

Parallel stack processing

Richer template language

Operate Fail-safe stack management

Updates without downtime

Federation and IAM roles

Page 39: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Parallel Stack Processing

Page 40: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Parallel Stack Processing

Page 41: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Richer Template Language

Page 42: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Conditions

Prod

Dev

Page 43: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Conditions "Parameters" : { "Environment" : { "Description" : "Specifies if this a Dev QA or Prod Environment", "Type" : "String", "Default" : "Dev", "AllowedValues" : [ "Dev", "QA", "Prod"] }, }, ... "Conditions" : { "ProdEnvironment" : { "Fn::Equals" : [ { "Ref" : "Environment" }, "Prod" ]} },

Page 44: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Conditions "DBInstance" : { "Type": "AWS::RDS::DBInstance", "Properties": { "DBName" : { "Ref" : "DBName" }, "Engine" : "MySQL", "MultiAZ" : { "Fn::If" : [ "ProdEnvironment", "true", "false" ] }, "DBSnapshotIdentifier" : { "Fn::If" : [ "ProdEnvironment", { "Ref" : "DBName" }, { "Ref" : "AWS::NoValue" } ] }, ... } },

Page 45: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Conditions "DBStorageAlarm" : { "Condition" : "ProdEnvironment", "Type" : "AWS::CloudWatch::Alarm", "Properties" : { "AlarmDescription" : "Alarm if db size grows beyond a threshold", "Namespace" : "AWS/RDS", "MetricName" : "FreeStorageSpace", ... } },

Page 46: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Conditions

• Fn::If • Fn::Equals • Fn::Not • Fn::And • Fn::Or

"Conditions" : { ... "ProdOrLoadTestingEnv" : { "Fn::Or" : [ { "Condition" : "ProdEnvironment"}, { "Fn::Equals" : [ ... ]} ] } }

"Fn::If": [{condition}, {value_if_true}, {value_if_false}]

Page 47: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

User-Defined Resource Names By default,

• AWS CloudFormation

generates unique resource names

• “prodstack20131113-DBStorageAlarm-19BL0MOXL0TPI”

In addition,

• Flexibility to use custom names and still keep them unique

• “SalesDataStorageAlarm”

Page 48: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Develop

Parallel stack processing

Richer template language

Operate Fail-safe stack management

Updates without downtime

Federation and IAM roles

Page 49: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Fail-Safe Stack Management

Page 50: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Stack Protection

CloudFormation Prod

Dev1

Dev2

Dev3

{ "Effect" : "Allow", "Action" : [ "cloudformation:*" ], "Resource" : "arn:aws:cloudformation:us-west- 2:123456789012:stack/Dev*" }

{ "Effect" : "Allow", "Action" : [ "cloudformation:*" ], "Resource" : "*" }

Page 51: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Stack Protection { "Effect" : "Deny", "Action" : [ "cloudformation:DeleteStack", "cloudformation:UpdateStack" ], "Resource" : "arn:aws:cloudformation:us-west-2:123456789012:stack/productionstack/*" }

Page 52: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Stack Protection "Resources" : { "StackProtectionPolicy" : { "Type" : "AWS::IAM::Policy", "Properties" : { "PolicyName" : "StackProtectionPolicy", "Groups" : [ { "Ref" : "DenyGrp" } ], "PolicyDocument" : { "Statement" : [ { "Effect" : "Deny", "Action" : [ "cloudformation:DeleteStack", "cloudformation:UpdateStack" ], "Resource" : { "Ref" : “AWS::StackId" } }

Page 53: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Resource Protection { "Effect" : "Deny", "Action" : [ "ec2:TerminateInstances" ], "Condition": { "Null": { "ec2:ResourceTag/*cloudformation*" : "true" } }, "Resource" : "*" }

Page 54: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Preventing Updates { "Statement" : [ { "Effect" : "Deny", "Action" : "Update:*", "Principal" : "*", "Resource" : "ResourceType/AWS::RDS::DBInstance" }, { "Effect" : "Allow", "Action" : "Update:*", "Principal" : "*", "Resource" : "*" } ] }

Stack Policy Document

Page 55: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Preventing Updates > aws cloudformation create-stack -–template-url ... --stack-policy-url ...

{ "Statement" : [ { "Effect" : "Deny", "Action" : "Update:Replace", "Principal" : "*", "Resource" : "LogicalResourceId/MyInstance" }, { "Effect" : "Allow", "Action" : "Update:*", "Principal" : "*", "Resource" : "*" ...

Fine Grained Stack Policy Setting Stack Policy

Page 56: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Update without Downtime "WebServerGroup" : { "Type" : "AWS::AutoScaling::AutoScalingGroup", "Properties" : { "LaunchConfigurationName" : { "Ref" : "LaunchConfig" }, ... }, "UpdatePolicy" : { "AutoScalingRollingUpdate" : { "MinInstancesInService" : “2", "MaxBatchSize" : “3", "PauseTime" : "PT20M" } } },

Page 57: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Using AWS CloudFormation with Federated Identities

Corporate identity store

1

User accesses broker

2 User authenticated

Identity broker

3 AWS Management

Console

User redirected to console

Temporary security credentials obtained

4

AWS Security Token Service

User accesses APIs

CloudFormation API and other AWS APIs

4

Network Architects

Application Developers

DB Admins

Page 58: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Calling AWS CloudFormation using IAM Roles

EC2 Instance

IAM Role

1. The IAM role has permissions to call

AWS CloudFormation and provision

underlying resources AWS CloudFormation

2. User or script on the EC2 instance calls CloudFormation to

provision a stack

3. AWS CloudFormation provisions the stack using a

template hosted in an S3 bucket inside the VPC

CloudFormation Stack

Page 59: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Related Resources • http://aws.amazon.com/cloudformation/

• "Fundamentals of CloudFormation" lab in the Self Paced Lab Lounge

• DMG303 - AWS CloudFormation under the Hood

• ARC203 - How Adobe Deploys: Refreshing the Entire Stack Every Time

• DMG209 - Enterprise Management for the AWS Cloud

• Multiple other sessions are presenting CloudFormation samples

Page 60: Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013

Please give us your feedback on this presentation

As a thank you, we will select prize winners daily for completed surveys!

DMG201