SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Auto Scaling on AWS
Matthew Swain
Software Engineer @ MassRelevance
What is AWS Auto Scaling?

Auto Scaling is Amazon’s hosted service for
automatically launching and terminating EC2
instances.
Why Use Auto Scaling

•

Save money by only using instances when you
need them.

•

Scale to accommodate expected and
unexpected loads.

•

Replace unhealthy servers with healthy ones.
What Makes Up Auto Scaling

•

Launch Configurations

•

Auto Scaling Groups

•

Scaling Policies

•

Cloud Watch Alarms
Launch Configurations

Templates that describe the parameters passed at
launch-time to your EC2 instances.
Examples: AMI, instance type (c1.xlarge, m1.small,
…), security groups, spot price
Auto Scaling Groups

A set of EC2 instances that run a launch
configuration.
Scaling Policies

A template describing actions to run against an
Auto Scaling Group.
E.g. Start two instances in the ASG named
“webservers”
Cloud Watch Alarms
Triggers that can run Scaling Policies based on
Cloud Watch metrics (AWS’s built in monitoring
suite).
E.g. Run Scaling Policy “Launch Webservers”
when CPU exceeds a certain threshold for 5
minutes.
A Simple Web Application in Five
Steps
•

Create an AMI

•

Setup an Elastic Load Balancer (ELB)

•

Create a Launch Configuration

•

Create Scaling Policies

•

Create Cloud Watch Alarms
Prerequisites

•

AWS Account

•

A running web application on an EBS backed
instance.

•

AWS Command Line tool:
http://aws.amazon.com/cli/
ZSH Auto-complete!
Build an AMI

aws ec2 create-image 
--instance-id i-12345678 
--name awesome-image-v1.0

output: ami-12345678
Create a Load Balancer

aws elb create-load-balancer 
--load-balancer-name 'my-lb' 
--listeners Protocol=http,
LoadBalancerPort=80,
InstanceProtocol=http,
InstancePort=80 
--availability-zones us-east-1d
Create a Launch Configuration

aws autoscaling create-launch-configuration 
--launch-configuration-name awesome-lc-v1.0 
--image-id ami-12345678 
--key-name my-keypair 
--securty-groups default 
--instance-type c1.xlarge
Create an Auto Scaling Group

aws autoscaling create-autoscaling-group 
--auto-scaling-group-name awesome-asg 
--launch-configuration-name awesome-lc-v1.0 
--min-size 1 
--max-size 10 
--desired-capacity 1 
--default-cooldown 120 
--availability-zones us-east-1d 
--load-balancer-names my-lb 
--health-check-type EC2
Create Scaling Policies

aws autoscaling put-scaling-policy 
--auto-scaling-group-name awesome-asg 
--policy-name awesome-asg-up 
--scaling-adjustment 1 
--adjustment-type ChangeInCapacity 
--cooldown 300

>> arn:aws:autoscaling<...>:policyName/awesome-asg-up
Create Scaling Policies

aws autoscaling put-scaling-policy 
--auto-scaling-group-name awesome-asg 
--policy-name awesome-asg-down 
--scaling-adjustment -1 
--adjustment-type ChangeInCapacity 
--cooldown 300

>> arn:aws:autoscaling<...>:policyName/awesome-asg-down
Create CloudWatch Alarms

aws cloudwatch put-metric-alarm 
--alarm-name awesome-cpu-high 
--metric-name CPUUtilization 
--actions-enabled 
--alarm-actions arn:aws:<...>:policyName/awesome-asg-up 
--namespace "AWS/EC2" 
--statistic Average 
--dimensions Name=AutoScalingGroupName,Value=awesome-asg 
--period 300 
--evaluation-periods 1 
--comparison-operator GreaterThanOrEqualToThreshold 
--threshold 60.0
Create CloudWatch Alarms

aws cloudwatch put-metric-alarm 
--alarm-name awesome-cpu-low 
--metric-name CPUUtilization 
--actions-enabled 
--alarm-actions arn:aws<...>policyName/awesome-asg-down 
--namespace "AWS/EC2" 
--statistic Average 
--dimensions Name=AutoScalingGroupName,Value=awesome-asg 
--period 300 
--evaluation-periods 1 
--comparison-operator LessThanOrEqualToThreshold 
--threshold 20.0
The AWS CloudWatch Console
The AWS CloudWatch Console
Advanced Usage

•

IAM Roles - Allow instances to access protected
S3 resources

•

UserData Scripts - Small bash startup scripts
passed to EC2 instances at boot time.

•

Chef - Client-Server Configuration Management
UserData Scripts
#!/bin/bash
role=fs
bootstrap=as-bootstrap-s3.sh
s3cmd_pkg=s3cmd-.tar.gz
PATH=$PATH:/usr/local/bin
cd /tmp
wget http://some-public-bucket/${s3cmd_pkg}
tar -xzf ${s3cmd_pkg}
cd `basename ${s3cmd_pkg} '.tar.gz'`
python setup.py install
cd /
s3cmd --config /dev/null get s3://private-bucket/${bootstrap}
chmod 755 ${bootstrap}
./${bootstrap} ${role} 2>&1 > ${bootstrap}.out
Questions?
Twitter: @mswain
Twitter: @mswain

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Day 5 - AWS Autoscaling Master Class - The New Capacity Plan
Day 5 - AWS Autoscaling Master Class - The New Capacity PlanDay 5 - AWS Autoscaling Master Class - The New Capacity Plan
Day 5 - AWS Autoscaling Master Class - The New Capacity Plan
 
AWS IAM과 친해지기 – 조이정, AWS 솔루션즈 아키텍트:: AWS Builders Online Series
AWS IAM과 친해지기 – 조이정, AWS 솔루션즈 아키텍트:: AWS Builders Online Series AWS IAM과 친해지기 – 조이정, AWS 솔루션즈 아키텍트:: AWS Builders Online Series
AWS IAM과 친해지기 – 조이정, AWS 솔루션즈 아키텍트:: AWS Builders Online Series
 
Amazon Route 53 - Webinar Presentation 9.16.2015
Amazon Route 53 - Webinar Presentation 9.16.2015Amazon Route 53 - Webinar Presentation 9.16.2015
Amazon Route 53 - Webinar Presentation 9.16.2015
 
Deep Dive on AWS Lambda
Deep Dive on AWS LambdaDeep Dive on AWS Lambda
Deep Dive on AWS Lambda
 
Elastic Load Balancing Deep Dive - AWS Online Tech Talk
Elastic  Load Balancing Deep Dive - AWS Online Tech TalkElastic  Load Balancing Deep Dive - AWS Online Tech Talk
Elastic Load Balancing Deep Dive - AWS Online Tech Talk
 
(DVO315) Log, Monitor and Analyze your IT with Amazon CloudWatch
(DVO315) Log, Monitor and Analyze your IT with Amazon CloudWatch(DVO315) Log, Monitor and Analyze your IT with Amazon CloudWatch
(DVO315) Log, Monitor and Analyze your IT with Amazon CloudWatch
 
Webinar AWS 201 - Using Amazon Virtual Private Cloud (VPC)
Webinar AWS 201 - Using Amazon Virtual Private Cloud (VPC)Webinar AWS 201 - Using Amazon Virtual Private Cloud (VPC)
Webinar AWS 201 - Using Amazon Virtual Private Cloud (VPC)
 
AWS CloudFormation Masterclass
AWS CloudFormation MasterclassAWS CloudFormation Masterclass
AWS CloudFormation Masterclass
 
AWS 101
AWS 101AWS 101
AWS 101
 
Amazon EC2 Masterclass
Amazon EC2 MasterclassAmazon EC2 Masterclass
Amazon EC2 Masterclass
 
Amazon CloudWatch Tutorial | AWS Certification | Cloud Monitoring Tools | AWS...
Amazon CloudWatch Tutorial | AWS Certification | Cloud Monitoring Tools | AWS...Amazon CloudWatch Tutorial | AWS Certification | Cloud Monitoring Tools | AWS...
Amazon CloudWatch Tutorial | AWS Certification | Cloud Monitoring Tools | AWS...
 
AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
 
AWS Connectivity, VPC Design and Security Pro Tips
AWS Connectivity, VPC Design and Security Pro TipsAWS Connectivity, VPC Design and Security Pro Tips
AWS Connectivity, VPC Design and Security Pro Tips
 
AWS 101: Introduction to AWS
AWS 101: Introduction to AWSAWS 101: Introduction to AWS
AWS 101: Introduction to AWS
 
Intro to AWS Lambda
Intro to AWS Lambda Intro to AWS Lambda
Intro to AWS Lambda
 
Getting Started with Amazon EC2
Getting Started with Amazon EC2Getting Started with Amazon EC2
Getting Started with Amazon EC2
 
Amazon S3 Masterclass
Amazon S3 MasterclassAmazon S3 Masterclass
Amazon S3 Masterclass
 
AWS Security Best Practices
AWS Security Best PracticesAWS Security Best Practices
AWS Security Best Practices
 
Auto Scaling Groups
Auto Scaling GroupsAuto Scaling Groups
Auto Scaling Groups
 
AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
 

Andere mochten auch

Adviento 2013
Adviento 2013Adviento 2013
Adviento 2013
MFCLA
 
Rpl biodiversity report new word version 2015
Rpl biodiversity report new word version 2015Rpl biodiversity report new word version 2015
Rpl biodiversity report new word version 2015
Ashlee Savage
 
The Longest Day Event 2015 - Alzheimer’s Association
The Longest Day Event 2015 - Alzheimer’s AssociationThe Longest Day Event 2015 - Alzheimer’s Association
The Longest Day Event 2015 - Alzheimer’s Association
Scott Robarge
 

Andere mochten auch (20)

AWS re:Invent 2016: Auto Scaling – the Fleet Management Solution for Planet E...
AWS re:Invent 2016: Auto Scaling – the Fleet Management Solution for Planet E...AWS re:Invent 2016: Auto Scaling – the Fleet Management Solution for Planet E...
AWS re:Invent 2016: Auto Scaling – the Fleet Management Solution for Planet E...
 
Auto Scaling AWS
Auto Scaling AWSAuto Scaling AWS
Auto Scaling AWS
 
How Does Amazon EC2 Auto Scaling Work
How Does Amazon EC2 Auto Scaling WorkHow Does Amazon EC2 Auto Scaling Work
How Does Amazon EC2 Auto Scaling Work
 
Proiektu Zientifikoa
Proiektu ZientifikoaProiektu Zientifikoa
Proiektu Zientifikoa
 
Three english lessons
Three english lessonsThree english lessons
Three english lessons
 
Deutsche Bank AG
Deutsche Bank AGDeutsche Bank AG
Deutsche Bank AG
 
Adviento 2013
Adviento 2013Adviento 2013
Adviento 2013
 
Practical insights in implementing lean principles Lean India Summit 2014
Practical insights in implementing lean principles Lean India Summit 2014Practical insights in implementing lean principles Lean India Summit 2014
Practical insights in implementing lean principles Lean India Summit 2014
 
Rpl biodiversity report new word version 2015
Rpl biodiversity report new word version 2015Rpl biodiversity report new word version 2015
Rpl biodiversity report new word version 2015
 
Recuperación Matemáticas
Recuperación MatemáticasRecuperación Matemáticas
Recuperación Matemáticas
 
The Longest Day Event 2015 - Alzheimer’s Association
The Longest Day Event 2015 - Alzheimer’s AssociationThe Longest Day Event 2015 - Alzheimer’s Association
The Longest Day Event 2015 - Alzheimer’s Association
 
Introduction to Digital humanities
Introduction to Digital humanitiesIntroduction to Digital humanities
Introduction to Digital humanities
 
Apple Devices History
Apple Devices HistoryApple Devices History
Apple Devices History
 
Get SunPowered
Get SunPoweredGet SunPowered
Get SunPowered
 
San Francisco Walk to End Alzheimer’s
San Francisco Walk to End Alzheimer’sSan Francisco Walk to End Alzheimer’s
San Francisco Walk to End Alzheimer’s
 
Kisley
KisleyKisley
Kisley
 
Lauroko geonautak
Lauroko geonautakLauroko geonautak
Lauroko geonautak
 
Doc1
Doc1Doc1
Doc1
 
Pest control
Pest controlPest control
Pest control
 
Ganesha Pooja and Mantra
Ganesha Pooja and MantraGanesha Pooja and Mantra
Ganesha Pooja and Mantra
 

Ähnlich wie Auto Scaling on AWS

Scalable and Fault-Tolerant Apps with AWS
Scalable and Fault-Tolerant Apps with AWSScalable and Fault-Tolerant Apps with AWS
Scalable and Fault-Tolerant Apps with AWS
Fernando Rodriguez
 

Ähnlich wie Auto Scaling on AWS (20)

All you need to know about Auto scaling - Pop-up Loft
All you need to know about Auto scaling - Pop-up LoftAll you need to know about Auto scaling - Pop-up Loft
All you need to know about Auto scaling - Pop-up Loft
 
Using AWS CloudWatch Custom Metrics and EC2 Auto Scaling -VSocial Infrastructure
Using AWS CloudWatch Custom Metrics and EC2 Auto Scaling -VSocial InfrastructureUsing AWS CloudWatch Custom Metrics and EC2 Auto Scaling -VSocial Infrastructure
Using AWS CloudWatch Custom Metrics and EC2 Auto Scaling -VSocial Infrastructure
 
Top 5 Ways to Optimize for Cost Efficiency with the Cloud
Top 5 Ways to Optimize for Cost Efficiency with the CloudTop 5 Ways to Optimize for Cost Efficiency with the Cloud
Top 5 Ways to Optimize for Cost Efficiency with the Cloud
 
오토스케일링 제대로 활용하기 (김일호) - AWS 웨비나 시리즈 2015
오토스케일링 제대로 활용하기 (김일호) - AWS 웨비나 시리즈 2015오토스케일링 제대로 활용하기 (김일호) - AWS 웨비나 시리즈 2015
오토스케일링 제대로 활용하기 (김일호) - AWS 웨비나 시리즈 2015
 
AutoScaling and Drupal
AutoScaling and DrupalAutoScaling and Drupal
AutoScaling and Drupal
 
Weaveworks at AWS re:Invent 2016: Operations Management with Amazon ECS
Weaveworks at AWS re:Invent 2016: Operations Management with Amazon ECSWeaveworks at AWS re:Invent 2016: Operations Management with Amazon ECS
Weaveworks at AWS re:Invent 2016: Operations Management with Amazon ECS
 
AWS AutoScaling
AWS AutoScalingAWS AutoScaling
AWS AutoScaling
 
Masterclass Live: Amazon EC2
Masterclass Live: Amazon EC2 Masterclass Live: Amazon EC2
Masterclass Live: Amazon EC2
 
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
 
Day 3 - Maintaining Performance & Availability While Lowering Costs with AWS
Day 3 - Maintaining Performance & Availability While Lowering Costs with AWSDay 3 - Maintaining Performance & Availability While Lowering Costs with AWS
Day 3 - Maintaining Performance & Availability While Lowering Costs with AWS
 
Scalable and Fault-Tolerant Apps with AWS
Scalable and Fault-Tolerant Apps with AWSScalable and Fault-Tolerant Apps with AWS
Scalable and Fault-Tolerant Apps with AWS
 
Harness the Power of Infrastructure as Code
Harness the Power of Infrastructure as CodeHarness the Power of Infrastructure as Code
Harness the Power of Infrastructure as Code
 
Amazon ECS Deep Dive
Amazon ECS Deep DiveAmazon ECS Deep Dive
Amazon ECS Deep Dive
 
AWS Public Sector Symposium 2014 Canberra | Managing Seasonal Workloads on AWS
AWS Public Sector Symposium 2014 Canberra | Managing Seasonal Workloads on AWS AWS Public Sector Symposium 2014 Canberra | Managing Seasonal Workloads on AWS
AWS Public Sector Symposium 2014 Canberra | Managing Seasonal Workloads on AWS
 
Running Lean Architectures
Running Lean ArchitecturesRunning Lean Architectures
Running Lean Architectures
 
Scaling drupal horizontally and in cloud
Scaling drupal horizontally and in cloudScaling drupal horizontally and in cloud
Scaling drupal horizontally and in cloud
 
Tech Talk: Autoscaling with Amazon Web Services
Tech Talk: Autoscaling with Amazon Web ServicesTech Talk: Autoscaling with Amazon Web Services
Tech Talk: Autoscaling with Amazon Web Services
 
Self Service Agile Infrastructure for Product Teams - Pop-up Loft Tel Aviv
Self Service Agile Infrastructure for Product Teams - Pop-up Loft Tel AvivSelf Service Agile Infrastructure for Product Teams - Pop-up Loft Tel Aviv
Self Service Agile Infrastructure for Product Teams - Pop-up Loft Tel Aviv
 
Day 2 - Amazon EC2 Masterclass - Getting the most from Amazon EC2
Day 2 - Amazon EC2 Masterclass - Getting the most from Amazon EC2Day 2 - Amazon EC2 Masterclass - Getting the most from Amazon EC2
Day 2 - Amazon EC2 Masterclass - Getting the most from Amazon EC2
 
Re:inventing EC2 Instance Launches with Launch Templates - SRV335 - Chicago A...
Re:inventing EC2 Instance Launches with Launch Templates - SRV335 - Chicago A...Re:inventing EC2 Instance Launches with Launch Templates - SRV335 - Chicago A...
Re:inventing EC2 Instance Launches with Launch Templates - SRV335 - Chicago A...
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Auto Scaling on AWS

  • 1. Auto Scaling on AWS Matthew Swain Software Engineer @ MassRelevance
  • 2. What is AWS Auto Scaling? Auto Scaling is Amazon’s hosted service for automatically launching and terminating EC2 instances.
  • 3. Why Use Auto Scaling • Save money by only using instances when you need them. • Scale to accommodate expected and unexpected loads. • Replace unhealthy servers with healthy ones.
  • 4. What Makes Up Auto Scaling • Launch Configurations • Auto Scaling Groups • Scaling Policies • Cloud Watch Alarms
  • 5. Launch Configurations Templates that describe the parameters passed at launch-time to your EC2 instances. Examples: AMI, instance type (c1.xlarge, m1.small, …), security groups, spot price
  • 6. Auto Scaling Groups A set of EC2 instances that run a launch configuration.
  • 7. Scaling Policies A template describing actions to run against an Auto Scaling Group. E.g. Start two instances in the ASG named “webservers”
  • 8. Cloud Watch Alarms Triggers that can run Scaling Policies based on Cloud Watch metrics (AWS’s built in monitoring suite). E.g. Run Scaling Policy “Launch Webservers” when CPU exceeds a certain threshold for 5 minutes.
  • 9. A Simple Web Application in Five Steps • Create an AMI • Setup an Elastic Load Balancer (ELB) • Create a Launch Configuration • Create Scaling Policies • Create Cloud Watch Alarms
  • 10. Prerequisites • AWS Account • A running web application on an EBS backed instance. • AWS Command Line tool: http://aws.amazon.com/cli/
  • 12. Build an AMI aws ec2 create-image --instance-id i-12345678 --name awesome-image-v1.0 output: ami-12345678
  • 13. Create a Load Balancer aws elb create-load-balancer --load-balancer-name 'my-lb' --listeners Protocol=http, LoadBalancerPort=80, InstanceProtocol=http, InstancePort=80 --availability-zones us-east-1d
  • 14. Create a Launch Configuration aws autoscaling create-launch-configuration --launch-configuration-name awesome-lc-v1.0 --image-id ami-12345678 --key-name my-keypair --securty-groups default --instance-type c1.xlarge
  • 15. Create an Auto Scaling Group aws autoscaling create-autoscaling-group --auto-scaling-group-name awesome-asg --launch-configuration-name awesome-lc-v1.0 --min-size 1 --max-size 10 --desired-capacity 1 --default-cooldown 120 --availability-zones us-east-1d --load-balancer-names my-lb --health-check-type EC2
  • 16. Create Scaling Policies aws autoscaling put-scaling-policy --auto-scaling-group-name awesome-asg --policy-name awesome-asg-up --scaling-adjustment 1 --adjustment-type ChangeInCapacity --cooldown 300 >> arn:aws:autoscaling<...>:policyName/awesome-asg-up
  • 17. Create Scaling Policies aws autoscaling put-scaling-policy --auto-scaling-group-name awesome-asg --policy-name awesome-asg-down --scaling-adjustment -1 --adjustment-type ChangeInCapacity --cooldown 300 >> arn:aws:autoscaling<...>:policyName/awesome-asg-down
  • 18. Create CloudWatch Alarms aws cloudwatch put-metric-alarm --alarm-name awesome-cpu-high --metric-name CPUUtilization --actions-enabled --alarm-actions arn:aws:<...>:policyName/awesome-asg-up --namespace "AWS/EC2" --statistic Average --dimensions Name=AutoScalingGroupName,Value=awesome-asg --period 300 --evaluation-periods 1 --comparison-operator GreaterThanOrEqualToThreshold --threshold 60.0
  • 19. Create CloudWatch Alarms aws cloudwatch put-metric-alarm --alarm-name awesome-cpu-low --metric-name CPUUtilization --actions-enabled --alarm-actions arn:aws<...>policyName/awesome-asg-down --namespace "AWS/EC2" --statistic Average --dimensions Name=AutoScalingGroupName,Value=awesome-asg --period 300 --evaluation-periods 1 --comparison-operator LessThanOrEqualToThreshold --threshold 20.0
  • 22. Advanced Usage • IAM Roles - Allow instances to access protected S3 resources • UserData Scripts - Small bash startup scripts passed to EC2 instances at boot time. • Chef - Client-Server Configuration Management
  • 23. UserData Scripts #!/bin/bash role=fs bootstrap=as-bootstrap-s3.sh s3cmd_pkg=s3cmd-.tar.gz PATH=$PATH:/usr/local/bin cd /tmp wget http://some-public-bucket/${s3cmd_pkg} tar -xzf ${s3cmd_pkg} cd `basename ${s3cmd_pkg} '.tar.gz'` python setup.py install cd / s3cmd --config /dev/null get s3://private-bucket/${bootstrap} chmod 755 ${bootstrap} ./${bootstrap} ${role} 2>&1 > ${bootstrap}.out

Hinweis der Redaktion

  1. What is AWS Auto Scaling? Put simply, Auto Scaling is Amazon’s hosted service for automatically launching and terminating EC2 instances.
  2. It’s really useful because it allows you to save money by only using AWS resources when you need them. For example, you can use it to help you accommodate peak loads without setting up huge amounts static infrastructure that runs all the time.
  3. So what makes up Amazon’s Auto Scaling service? It’s actually comprised of different components that work in concert to allow you to automatically adjust your environment to meet your needs. The four basic components are: Launch Configurations, Auto Scaling Groups, Scaling Policies, and Cloud Watch Alarms. There are a few more pieces I’m glossing over, but these are the fundamental building blocks.
  4. The first component, “Launch Configurations” are templates that define the parameters passed to your EC2 instances at launch time. For example, your launch configurations will define what size instance to run, which security group they will run in, etc. You can even specify things like “spot price” if you want to take advantage of Amazon’s spot instance pricing.
  5. The next component is the “Autoscaling Group” An Auto Scaling Group is a collection of EC2 instances that run a launch configuration.
  6. The third basic component is the “Scaling Policy.” Scaling policies are declarative templates that define an action to take on your autoscaling group. For example, “start two instances in the ASG named “webservers”
  7. The last basic component is the “Cloud Watch Alarm”. These are triggers that execute scaling polices based on metrics measured in Amazon’s CloudWatch monitoring service.
  8. So how do these components work together? To illustrate this, I’ll walk through a simple example. I’ll set up a very basic Auto Scaling service in five steps. In this example, my goal is to set up an environment that will launch and terminate servers based on CPU Utilization across my cluster.
  9. To run through this example, I’ll assume the following things have already been done. First we have an AWS account :) In it, I’ll assume I’m already running a web application on an EBS backed instance. And finally I’ll assume we’re going to use the new unified AWS command line tool.
  10. If you haven’t checked out the new AWS command line tool, it’s really nice. It even ships with an excellent set of autocomplete scripts. So entering commands really isn’t that painful. Everything is a Tab key press away. But I digress…
  11. So for the first step, I’ll create an AMI of my instance. Here the instance id of my existing server is i-12345678. Hopefully it’s a web service that has a nice health check for a load balancer to detect when it’s down, and hopefully the web service on it can stop and start gracefully. Once I run this command, it will output an AMI ID we’ll use in later steps.
  12. The next step is to create a load balancer that will route requests to my web server. This command will create an empty load balancer that forwards HTTP requests on port 80 to, similarly, port 80 on the instances that are attached to it.
  13. Next, we’ll create a launch configuration. This Launch Configuration will start servers using the AMI we defined in step one. I’m also describing the standard AWS parameters such as “instance type,” “key-pair,” and “security-groups” that you need when starting any EC2 instance.
  14. Once I have my Launch Configuration setup, I can create my Auto Scaling Group. Here I’m defining important parameters such as the minimum number of instances to run in the group, as well as the maximum number of instances allowed. I’m also setting up this group to attach instances to the ELB I created in step 2. Some other parameters of note: default-cooldown will set a default number of seconds that an autoscaling group will prevent actions from occurring against it. Specifically this means that if a policy executed against this group, it will wait 120 seconds before allowing another policy to run against it. The “—health-check-type” parameter indicates how Amazon will determine if a node in this group has failed. This can be one of two values, ELB or EC2. Here I’m setting it to “EC2” which is a basic ping check Amazon internally runs. If a node fails this check, the Auto Scaling group will kill the instance and replace it with another one.
  15. Next, we’ll create 2 polices. This one increases the number of instances in your ASG by one. Note that we can override the cooldown we specified on the Auto Scaling Group. This way different scaling policies can prevent actions from occurring against the group for different amounts of time. Once we run this command it will output a huge ARN, which is an internal identifier that describes this policy. We’ll use this ARN later to hook up to our cloud watch alarms.
  16. Similarly, this policy says “change the capacity of the ASG by negative one.” Or, more simply, terminate one instance. Again, this will spit out an ARN we will use later.
  17. The last thing we’ll do is create 2 cloud watch alarms. This one will trigger the scale up policy when the Average CPU utilization across the entire ASG goes above 60% for 5 minutes. Note the —alarm-action parameter. This is the giant ARN that was spit out when we created the scale up policy.
  18. Similarly, this is the alarm that will trigger the scale-down policy. It basically says, run the scale down policy when the average cpu utilization across all the instances in the ASG is less than or equal to 20%
  19. And bam. That’s all there is to it. Now we have an autoscaling group that will dynamically launch and terminate instances based on CPU load. While the other ASG tools don’t have a GUI representation, you can actually log into the AWS console and look at graphs corresponding to your Cloud Watch alarms. This is an example from our production cluster at Mass Relevance. Here you can see red lines that correspond to where the triggers are set. When an alarm triggers, it’s entire graph turns red indicating that it is firing. In this state, it is executing any autoscaling policies associated with it.
  20. Here’s another example of our production cluster’s cloud watch console. This was a special event that occurred on October 29th. Our auto scaling configuration handled this perfectly, meaning we didn’t have to actually do anything to handle this increase in load. Autoscale added and removed the instances as needed so we could sleep at night without too much worry.
  21. So now I’ll talk about some advanced uses. At MR we don’t rely on pre-built AMI’s. Instead, all of our instances are built using chef. Luckily AWS gives you the tools to do this, too. In our environment, we use a combination of IAM roles, S3, and user-data scripts to hook up our instances to our Chef server. Specifically, we have an IAM role that allows instances to access a private S3 bucket that host scripts and packages that setup our chef client. User Data scripts are small shell scripts that EC2 instances will execute on boot time. So in our case, we pass a User Data script to our Launch Configuration. This script will leverage the IAM role to download our chef client from S3, set it up, and kick it off.
  22. This is an example of the User Data Script we use to do this. All in all it’s been a very effective setup that has allowed us to scale for all sorts of events. For example, at the grammy’s we were pushing a peak loads of 80k requests per second. At the time we were running close to 200 web servers, worker servers, and caching servers to handle the load. All of these were launched and managed with autoscale, albeit with lots of pre-warming. After the event was over, we scaled back down to around something like 10 servers… which is our typical baseline.
  23. So that about wraps it up. Are there any questions?