Page 1
© 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
Page 2
Featuring
Sudhindra R Rao and Pengchao Wang,
ThoughtWorks
Page 3
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!
Page 4
Under the Hood Series
• Elastic Beanstalk experience assumed
• Practical tips and tricks
• Real stories, real advice, from real customers
• Q&A!
Page 5
Flow
AWS (25m)
ThoughtWorks (25m)
Q&A (10m)
Page 6
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
Page 7
Resource Lifetime
Alert
Log
Mon A
pp
AZ
EL
B
Terminate
environment
http://www.your-app.com
Page 8
Resource Lifetime
Alert
Log
Mon A
pp
AZ
EL
B
Terminate
environment
http://www.your-app.com
Page 9
A CloudFormation Template
• Demo
Page 10
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)
Page 11
Adding Resources Using EBExtensions
Alert
Log
Mon Ap
p
AZ
EL
B
http://www.your-app.com
EBS EBS
Page 12
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
Page 13
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"
Page 14
Extending Your Configuration
• Adding additional resources (Alarm and Topic)
AlarmTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint:
Fn::GetOptionSetting:
OptionName: AlarmEmail
DefaultValue: "[email protected] "
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
Page 15
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.
Page 16
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
Page 17
Using Branches
Users
git commit Branch1
Branch2
Git repository
V1
V2
V1
V2
Page 18
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
Page 19
Zero Downtime Deployments
• Deploy new version with zero downtime and
ability to roll back (i.e., CNAME swap)
Page 20
http://www.your-app.com
V1 V1
Page 21
http://www.your-app.com
V1 V1
Page 22
http://www.your-app.com
V1 V1 V2 V2
Page 23
http://www.your-app.com
V1 V1 V2 V2
Page 24
http://www.your-app.com
V1 V1 V2 V2
Page 25
http://www.your-app.com
V1 V1 V2 V2
Page 26
http://www.your-app.com
V1 V1 V2 V2
Page 27
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
Page 28
Controlling Traffic
http://your-app.com
Weight 100
Weight 0
V2 V2
V1 V1
Page 29
Controlling Traffic
http://your-app.com
Weight 100
Weight 10
V2 V2
V1 V1
Page 30
Controlling Traffic
http://your-app.com
Weight 0
Weight 100
V2 V2
V1 V1
Page 31
Controlling Traffic
• Demo
Page 32
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
Page 33
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
Page 34
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
Page 35
Sudhindra R Rao and Pengchao Wang
Page 36
Blue-Green Deployments with AWS
Elastic Beanstalk
Page 37
Elastic Beanstalk
I am so
beautiful
!
Page 38
Elastic Beanstalk – Missing Parts?
Automated Blue-Green
Deployments
Page 39
http://thoughtworksstudios.github.io/eb_deployer
AWS Elastic Beanstalk blue-green deployment automation
Page 40
Blue Green Deployments on Elastic Beanstalk
version n
version n+1 testing
terminate
Page 41
EbDeployer Automates Blue-Green Deployments
Page 42
Deployment with EbDeployer
version n
version n+1 smoke tests
scale down
Page 43
Package and Deploy
Page 44
A Sample Smoke Test
Page 46
EbDeployer Makes Shared Resource
Blue-Green Deployments Easier
Page 47
Elastic Beanstalk Resource Management
version n
version n+1
Page 48
Shared Resources
version n
version n+1
Page 49
EbDeployer
Adding RDS to the Deployment
Page 50
Add a CloudFormation Template for RDS
Page 51
Add Resource Declaration
Page 53
EbDeployer Provides Different
Deployment Flavors
Page 54
• phoenix_mode: true
Phoenix Server
Page 55
Deployment Strategy
• blue-green vs. inplace-update
Page 56
EbDeployer in Our Pipeline
Page 57
Continuous Delivery
Page 59
Have a Pull Request?
http://thoughtworksstudios.github.io/eb_deployer
[email protected] @alexhal9000
[email protected] @sudhindraRao
Page 60
Please give us your feedback on this
presentation
As a thank you, we will select prize
winners daily for completed surveys!
DMG301