AWS Elastic Beanstalk under the Hood (DMG301) | AWS re:Invent 2013

Post on 15-Jan-2015

4.822 views 1 download

Tags:

description

AWS Elastic Beanstalk provides a number of simple, flexible interfaces for developing and deploying your applications. In this session, learn how ThoughtWorks leverage the Elastic Beanstalk API to continuously deliver their applications with smoke tests and blue-green deployments. Also learn how to deploy your apps with Git and eb, a powerful CLI that allows developers to create, configure, and manage Elastic Beanstalk applications and environments from the command line.

Transcript of AWS Elastic Beanstalk under the Hood (DMG301) | 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.

DMG301 – AWS Elastic Beanstalk Under the Hood

Chris Whitaker, Amazon Web Services

November 14, 2013

Featuring

Sudhindra R Rao and Pengchao Wang,

ThoughtWorks

Have you ever wanted to…

• Control the lifetime of your AWS resources

separately from your application code?

• Extend or add more AWS resources to your

Elastic Beanstalk environment?

• Control traffic to your application as you deploy?

You have come to the right place!

Under the Hood Series

• Elastic Beanstalk experience assumed

• Practical tips and tricks

• Real stories, real advice, from real customers

• Q&A!

Flow

AWS (25m)

ThoughtWorks (25m)

Q&A (10m)

Controlling the Lifetime

• Out-of-the-box Elastic Beanstalk supports – Amazon Relational Database Service (RDS)

• Tied to the lifetime of your environment – Terminating or rebuilding your environment removes or replaces

your database

• Use AWS CloudFormation to manage resource

lifetimes independently

Resource Lifetime

Alert

Log

Mon A

pp

AZ

EL

B

Terminate

environment

http://www.your-app.com

Resource Lifetime

Alert

Log

Mon A

pp

AZ

EL

B

Terminate

environment

http://www.your-app.com

A CloudFormation Template

• Demo

Extending Your Configuration

• Elastic Beanstalk gives you the following: – Load balanced, auto scaling; single instance

– Amazon RDS database

• What if your application needs other resources – Amazon ElastiCache cache cluster, Amazon DynamoDB table,

Amazon Elastic Block Store (EBS) volumes, Amazon CloudWatch alarms…

• Two options – Elastic Beanstalk extensions (resources with lifetime tied to the code or

instance)

– AWS CloudFormation templates (resources with independent lifetime)

Adding Resources Using EBExtensions

Alert

Log

Mon Ap

p

AZ

EL

B

http://www.your-app.com

EBS EBS

Adding Resources using CloudFormation

Alert

Log

Mon Ap

p

AZ

EL

B

http://www.your-app.com

option_settings:

"aws:autoscaling:launchconfiguation":

InstanceType: "m1.large"

BlockDeviceMappings: "/dev/sdj:100"

Resources:

AlarmTopic:

Type: AWS::SNS::Topic

Properties: …

CpuAlarm:

Type: AWS::CloudWatch::Alarm

Properties…

EBS EBS

create_resources.config

Extending Your Configuration

• Attach an EBS-optimized volume

• Supported directly by Elastic Beanstalk

option_settings:

"aws:autoscaling:launchconfiguation":

InstanceType: "m1.large"

BlockDeviceMappings: "/dev/sdj:100"

Extending Your Configuration

• Adding additional resources (Alarm and Topic)

AlarmTopic:

Type: AWS::SNS::Topic

Properties:

Subscription:

- Endpoint:

Fn::GetOptionSetting:

OptionName: AlarmEmail

DefaultValue: "nobody@amazon.com"

Protocol: email

CpuAlarm:

Type: AWS::CloudWatch::Alarm

Properties:

AlarmDescription: "Alarm if CPU grows beyond 90%"

Namespace: "AWS/EC2"

MetricName: CPUUtilization

Dimensions:

- Name: AutoScalingGroupName

Value : { "Ref" : "AWSEBAutoScalingGroup" }

Statistic: Average

Period: 300

EvaluationPeriods: 1

Threshold: 90

ComparisonOperator: GreaterThanThreshold

AlarmActions:

- Ref: AlarmTopic

Built-in Resources Resource Name Description

AWSEBAutoScalingGroup The name of the Auto Scaling group that Elastic Beanstalk uses

when it launches Amazon EC2 instances.

AWSEBAutoScalingLaunchConfiguration The name for the launch configuration settings that Elastic

Beanstalk uses when it launches EC2 instances.

AWSEBEnvironmentName The name of the Elastic Beanstalk environment.

AWSEBLoadBalancer The name of the elastic load balancer used in the Elastic Beanstalk

environment.

AWSEBRDSDatabase The name of the Amazon RDS database.

AWSEBSecurityGroup The name for the EC2 security group that Elastic Beanstalk uses

when it launches EC2 instances.

Advanced Deployment Techniques

• Deploying to QA and Production using branches – Use multiple Git branches deployed to multiple environments

• Zero downtime deployments using CNAME flip – Deploy a new version even under heavy load

• Controlling traffic using Amazon Route 53 – Define how much traffic is directed to your new version

Using Branches

Users

git commit Branch1

Branch2

Git repository

V1

V2

V1

V2

Deploying Using Multiple Branches

git init

eb init

git add .

… edit your source

git commit

git aws.push

git branch v1

git checkout v1

eb branch

git aws.push

git checkout master

… edit your source

git aws.push

Test cycle deployed to test

Create a V1 branch and deploy

to production

Continue to develop and test

Zero Downtime Deployments

• Deploy new version with zero downtime and

ability to roll back (i.e., CNAME swap)

http://www.your-app.com

V1 V1

http://www.your-app.com

V1 V1

http://www.your-app.com

V1 V1 V2 V2

http://www.your-app.com

V1 V1 V2 V2

http://www.your-app.com

V1 V1 V2 V2

http://www.your-app.com

V1 V1 V2 V2

http://www.your-app.com

V1 V1 V2 V2

Controlling Traffic

• What if you want more control of the traffic when

you deploy a new version?

• Use Amazon Route 53 weighted resource

record sets – Associate multiple Elastic Beanstalk environments with the

same DNS name

– Control traffic flow using weights

Controlling Traffic

http://your-app.com

Weight 100

Weight 0

V2 V2

V1 V1

Controlling Traffic

http://your-app.com

Weight 100

Weight 10

V2 V2

V1 V1

Controlling Traffic

http://your-app.com

Weight 0

Weight 100

V2 V2

V1 V1

Controlling Traffic

• Demo

Geographic Load Balancing

• Extend the Amazon Route53 idea to use latency

record sets – Associate multiple Elastic Beanstalk environments in different

regions with the same DNS name

– Latency-based routing selects the “nearest” Elastic Beanstalk

environment

Call to Action

• Customize your infrastructure with EBExtensions

• Use AWS CloudFormation in conjunction with Elastic Beanstalk to control resources lifetime

• Deploy using multiple branches for development and production

• Use CNAME flip or Amazon Route 53 configuration to manage your deployments

Other Resources

• DMG204 - Zero to Sixty: AWS Elastic Beanstalk

• DMG201 - Zero to Sixty: AWS CloudFormation

• DMG303 - AWS CloudFormation Under the Hood

Come find me in the developer resources booth

Sudhindra R Rao and Pengchao Wang

Blue-Green Deployments with AWS

Elastic Beanstalk

Elastic Beanstalk

I am so

beautiful

!

Elastic Beanstalk – Missing Parts?

Automated Blue-Green

Deployments

http://thoughtworksstudios.github.io/eb_deployer

AWS Elastic Beanstalk blue-green deployment automation

Blue Green Deployments on Elastic Beanstalk

version n

version n+1 testing

terminate

EbDeployer Automates Blue-Green Deployments

Deployment with EbDeployer

version n

version n+1 smoke tests

scale down

Package and Deploy

A Sample Smoke Test

Demo

EbDeployer Makes Shared Resource

Blue-Green Deployments Easier

Elastic Beanstalk Resource Management

version n

version n+1

Shared Resources

version n

version n+1

EbDeployer

Adding RDS to the Deployment

Add a CloudFormation Template for RDS

Add Resource Declaration

Demo

EbDeployer Provides Different

Deployment Flavors

• phoenix_mode: true

Phoenix Server

Deployment Strategy

• blue-green vs. inplace-update

EbDeployer in Our Pipeline

Continuous Delivery

EbDeployer

Have a Pull Request?

http://thoughtworksstudios.github.io/eb_deployer

wpc@thoughtworks.com @alexhal9000

srao@thoughtworks.com @sudhindraRao

Please give us your feedback on this

presentation

As a thank you, we will select prize

winners daily for completed surveys!

DMG301