SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
Auto Scaling Groups 
Advanced AWS meetup 
! 
! 
! 
Peter Sankauskas 
Founder of CloudNative 
@pas256 
https://cloudnative.io/ @pas256
Daily life 
More users 
More instances 
More data More logs 
Higher costs 
New engineers 
Increased deployment frequency 
Reduce costs 
Boss 
Eliminate deployment risks 
Deadline 
https://cloudnative.io/ @pas256
Your Goal 
Sleep 
Reliable 
Social life 
Sleep 
Uptime 
Time with family 
Sleep 
https://cloudnative.io/ @pas256
“Don’t hate the Pager, hate the game” 
– PagerDuty 
https://cloudnative.io/ @pas256
Old world 
Instances running 
11 
9 
7 
4 
2 
0 
70% Wasted 
Used Capacity 
https://cloudnative.io/ @pas256
Auto Scaling Group 
• Your assistant in the cloud 
• First level support 
• Automation 
11 
9 
7 
4 
2 
0 
Used Capacity 
https://cloudnative.io/ @pas256
Auto Scaling Group 
• Capacity: minimum, maximum, desired 
• Access: ELB 
• Polices 
• Where: 
• Availability Zones 
• VPC Subnets 
ASG Launch Config 
Scaling Policy 
Scaling Policy 
Scaling Policy 
Scheduled 
Scheduled 
Action 
Scheduled 
Action 
Action 
https://cloudnative.io/ @pas256
{! 
"Type" : "AWS::AutoScaling::AutoScalingGroup",! 
"Properties" : {! 
"AvailabilityZones": [ String, ... ],! 
"Cooldown": String,! 
"DesiredCapacity": String,! 
"HealthCheckGracePeriod": Integer,! 
"HealthCheckType": String,! 
“LaunchConfigurationName": String,! 
"LoadBalancerNames": [ String, ... ],! 
"MaxSize": String,! 
"MetricsCollection": [ MetricsCollection, ... ]! 
"MinSize": String,! 
“NotificationConfiguration": NotificationConfiguration,! 
"PlacementGroup": String,! 
"Tags": [ Auto Scaling Tag, ... ],! 
“TerminationPolicies": [ String, ... ],! 
"VPCZoneIdentifier": [ String, ... ]! 
}! 
} 
https://cloudnative.io/ @pas256
Launch Configuration 
• Every ASG needs a Launch Configuration 
• Describes what an individual EC2 instance looks like 
• AMI 
• Instance type 
• Security groups 
https://cloudnative.io/ @pas256
{! 
"Type" : "AWS::AutoScaling::LaunchConfiguration",! 
"Properties" : {! 
"AssociatePublicIpAddress": Boolean,! 
"BlockDeviceMappings": [ BlockDeviceMapping, ... ],! 
"EbsOptimized": Boolean,! 
"IamInstanceProfile": String,! 
"ImageId": String,! 
"InstanceMonitoring": Boolean,! 
"InstanceType": String,! 
"KernelId": String,! 
"KeyName": String,! 
"RamDiskId": String,! 
"SecurityGroups": [ SecurityGroup, ... ],! 
"SpotPrice": String,! 
"UserData": String! 
}! 
} 
https://cloudnative.io/ @pas256
Scaling Plans 
1. Fixed 
2. Manual 
3. Scheduled 
4. Dynamic 
https://cloudnative.io/ @pas256
Fixed 
• Ensure a fixed number of instances is always running 
• Set MinSize = MaxSize 
• Examples 
• Any “master” service 
• Zookeeper - 3 nodes across 3 AZs 
• Cassandra 
3 
2 
1 
0 
Used Capacity 
https://cloudnative.io/ @pas256
# One Asgard instance - troposphere example! 
launchConfig = t.add_resource(asg.LaunchConfiguration("launchConf",! 
AssociatePublicIpAddress=True,! 
IamInstanceProfile=Ref(asgardInstanceProfile),! 
ImageId=FindInMap("AWSRegion2AMI", Ref("AWS::Region"), "AMI"),! 
InstanceType="m3.medium",! 
KeyName="admin",! 
SecurityGroups=[Ref(asgardInstanceSecurityGroup)],! 
))! 
! 
asgardASG = t.add_resource(asg.AutoScalingGroup("asgardASG",! 
Tags=[asg.Tag("Name", "Asgard", True)],! 
Cooldown="120",! 
MinSize="1",! 
MaxSize="1",! 
AvailabilityZones=["us-west-2a","us-west-2b"],! 
VPCZoneIdentifier=["subnet-c46c6982","subnet-8133f6e4"],! 
LaunchConfigurationName=Ref(asgardLaunchConfig),! 
)) 
https://cloudnative.io/ @pas256
Manual Scaling 
• Use API to change capacity on demand 
SetDesiredCapacity! 
• AutoScalingGroupName = my-asg 
• DesiredCapacity = 2 
2 
1 
0 
Used Capacity 
https://cloudnative.io/ @pas256
Scheduled 
• At this time, set capacity to X 
• Each ScheduledAction must have a 
unique start time 
• Guaranteed order of execution 
within same ASG 
11 
9 
7 
4 
2 
0 
Used Capacity 
https://cloudnative.io/ @pas256
Specific date and time 
PutScheduledUpdateGroupAction! 
• ScheduledActionName = ScaleOut 
• AutoScalingGroupName = my-asg 
• DesiredCapacity = 3 
• StartTime = “2013-05-12T08:00:00Z” 
https://cloudnative.io/ @pas256
Recurring schedule 
PutScheduledUpdateGroupAction! 
• ScheduledActionName = Scaleout-schedule-year 
• AutoScalingGroupName = my-asg 
• DesiredCapacity = 3 
• Recurrence = “30 0 1 1,6,12 0” 
https://cloudnative.io/ @pas256
Dynamic Scaling 
• Best Utilization 
• Lowest Cost 
11 
9 
7 
4 
2 
0 
Used Capacity 
https://cloudnative.io/ @pas256
Trigger: CloudWatch Alarm 
• Metrics 
• CPU Utilization 
• Network in/out 
• Size of queue (SQS) 
• Anything you put into CloudWatch 
• Set the Alarm Action to the ARN of the ScalingPolicy 
https://cloudnative.io/ @pas256
Action: ScalingPolicy 
• Adjustment Types 
• Change by number 
• E.g. Scale Out: Add 2 more instances 
• E.g. Scale In: Remove 1 instances 
• Exact 
• E.g. Scale Out: Have exactly 8 instances 
• Percentage 
• E.g. Scale Out: Add 25% more instances 
https://cloudnative.io/ @pas256
Cooldown 
• After a ScalingPolicy has been fired, wait X seconds before 
performing any other actions. 
• Manual Scaling: SetDesiredCapacity 
• HonorCoolDown = True/False 
https://cloudnative.io/ @pas256
Load Balancing 
• Put an ELB in front of the instance in your ASG 
• Set when creating the ASG 
• Zero effort in adding and removing instances 
• Additional health check options 
https://cloudnative.io/ @pas256
Health Checks 
• By default, ASG uses EC2 Status Checks 
• If you have an ELB, you can use the same ELB health checks 
• HTTP:80/healthcheck! 
• HTTP 200 response is the only thing that is considered healthy 
• E.g. Return something else while app is loading filled 
https://cloudnative.io/ @pas256
Termination Policy 
• OldestInstance 
• NewestInstance 
• OldestLaunchConfiguration 
• ClosestToNextInstanceHour 
https://cloudnative.io/ @pas256
https://cloudnative.io/ @pas256
Requirements for Dynamic Scaling 
• Stateless application 
• Configuration must be 100% automated 
• Tools understand dynamic environments 
• Config management 
• Monitoring 
• Log aggregation 
https://cloudnative.io/ @pas256
https://cloudnative.io/ @pas256
Migration 
• Create an ASG or LaunchConfiguration from an already running 
instance 
• Put that instance in the ASG 
https://cloudnative.io/ @pas256
{! 
"Type" : "AWS::AutoScaling::AutoScalingGroup",! 
"Properties" : {! 
"AvailabilityZones" : [ String, ... ],! 
"Cooldown" : String,! 
"DesiredCapacity" : String,! 
"HealthCheckGracePeriod" : Integer,! 
"HealthCheckType" : String,! 
"InstanceId" : String,! 
"LaunchConfigurationName" : String,! 
"LoadBalancerNames" : [ String, ... ],! 
"MaxSize" : String,! 
"MetricsCollection" : [ MetricsCollection, ... ]! 
"MinSize" : String,! 
"NotificationConfiguration" : NotificationConfiguration,! 
"PlacementGroup" : String,! 
"Tags" : [ Auto Scaling Tag, ... ],! 
"TerminationPolicies" : [ String, ... ],! 
"VPCZoneIdentifier" : [ String, ... ]! 
}! 
} 
https://cloudnative.io/ @pas256
{! 
"Type" : "AWS::AutoScaling::LaunchConfiguration",! 
"Properties" : {! 
"AssociatePublicIpAddress" : Boolean,! 
"BlockDeviceMappings" : [ BlockDeviceMapping, ... ],! 
"EbsOptimized" : Boolean,! 
"IamInstanceProfile" : String,! 
"ImageId" : String,! 
"InstanceId" : String,! 
"InstanceMonitoring" : Boolean,! 
"InstanceType" : String,! 
"KernelId" : String,! 
"KeyName" : String,! 
"RamDiskId" : String,! 
"SecurityGroups" : [ SecurityGroup, ... ],! 
"SpotPrice" : String,! 
"UserData" : String! 
}! 
} 
https://cloudnative.io/ @pas256
# Instance Configuration - Self healing NAT - troposphere! 
natLaunchConfig = t.add_resource(asg.LaunchConfiguration(! 
"natLaunchConfig",! 
AssociatePublicIpAddress=True,! 
InstanceType="t1.micro",! 
ImageId="ami-f032acc0",! 
SecurityGroups=[Ref(natSecurityGroup)],! 
IamInstanceProfile=Ref(natInstanceProfile),! 
UserData=Base64(Join("n", [! 
"#!/bin/bash",! 
"yum update -y",! 
"instanceId=`/opt/aws/bin/ec2-metadata -i | cut -f2 -d' '`",! 
"region=`/opt/aws/bin/ec2-metadata -z | cut -f2 -d' ' | sed '$s/.$//'`",! 
"vpcId=`aws ec2 describe-instances --instance-ids $instanceId --region $region --query 
'Reservations[*].Instances[*].VpcId' --output text`",! 
"""rtbId=`aws ec2 describe-route-tables --region $region --filters "[{"Name":"vpc-id"," 
Values":["$vpcId"]},{"Name":"association.main","Values":["true 
"]}]" --query RouteTables[*].RouteTableId --output text`""",! 
"""aws ec2 modify-instance-attribute --instance-id $instanceId --source-dest-check 
'{"Value": false}' --region $region --output table""",! 
"aws ec2 replace-route --route-table-id $rtbId --destination-cidr-block 0.0.0.0/0 -- 
instance-id $instanceId --region $region --output table",! 
"aws ec2 create-route --route-table-id $rtbId --destination-cidr-block 0.0.0.0/0 -- 
instance-id $instanceId --region $region --output table"! 
]))! 
)) 
https://cloudnative.io/ @pas256
UserData and cloud-init 
• Inside LaunchConfiguration 
• Set UserData script to be run by cloud-init 
• If you are using Chef, this is what you will do 
• More details: 
• Watch Episode #4 on Answers for AWS 
https://cloudnative.io/ @pas256
Baking AMIs 
• Raw: Do everything on boot 
• Fully Baked: Immutable infrastructure 
• Half-Baked: Anything in-between 
! 
http://answersforaws.com/blog/2013/11/half-baked/ 
https://cloudnative.io/ @pas256
Deploy Changes 
• Option 1: Change AMI or User Data in LaunchConfiguration 
• NOTE: This has no immediate outcome 
• Only affects newly launched instances 
• Revisit TerminatePolicy 
• You need to terminate existing instances so that new ones come 
up with the changes 
https://cloudnative.io/ @pas256
Deploy Changes 
• Option 2: Create a completely new stack 
• Use CloudFormation (or whatever) to create a new ASG, 
LaunchConfig, ScalingPolicies, ELB, Security Group, VPC, Subnets, 
etc 
• Overkill 
• If you have high traffic, the new ELB will not be pre-scaled and will not 
handle the load 
• Need to contact AWS TAM 
https://cloudnative.io/ @pas256
Blue/Green Deployment 
Or is a red/black deployment… or is it A/B deployment? 
• Option 3: 
• Reuse existing infrastructure including the same ELB 
• Create a new ASG and LaunchConfig 
• Switch traffic at the ELB from old ASG to new ASG 
https://cloudnative.io/ @pas256
Demo 
https://cloudnative.io/ @pas256
“It’s not about how fast you can deploy, it is about how fast you 
can rollback” 
– Peter Sankauskas… just now 
https://cloudnative.io/ @pas256
Canary Deployment 
• Very similar to blue/green deployment 
• New ASG and LaunchConfig 
• Add traffic to only 1 instance in the new ASG 
• Then 2 instance 
• Up to 100% 
• Both versions running side by side 
• Roll off traffic from old ASG instances 
https://cloudnative.io/ @pas256
Running multiple version 
• DB Schema changes are on a different schedule to code 
deployments 
• mcfunley (Etsy): “We deploy schema changes once per week. The 
code always works against both versions of the schema. We never 
take downtime for schema changes. We avoid data loss by doing 
soft deletes as much as we can.” 
• Deploy features dark 
• Use Feature Flags 
https://cloudnative.io/ @pas256
Tools 
• Baking AMIs 
• Packer - Hashicorp 
• Aminator - Netflix 
• CloudNative 
• Deployment 
• Asgard - Netflix 
• CloudNative 
https://cloudnative.io/ @pas256
New World 
• Automation expert 
• Stateless, independently scalable 
apps 
• Allergic to manual labor 
• Embrace your laziness 
• Auto Scaling Groups provide: 
• Zero-effort scaling 
• Fault-tolerance 
• Increase reliability & uptime 
• Decrease cost 
https://cloudnative.io/ @pas256
Sleep 
https://cloudnative.io/ @pas256

Contenu connexe

Tendances

Amazon EC2 Deep Dive - 이창수 (AWS 솔루션 아키텍트) : 8월 온라인 세미나
Amazon EC2 Deep Dive - 이창수 (AWS 솔루션 아키텍트) : 8월 온라인 세미나Amazon EC2 Deep Dive - 이창수 (AWS 솔루션 아키텍트) : 8월 온라인 세미나
Amazon EC2 Deep Dive - 이창수 (AWS 솔루션 아키텍트) : 8월 온라인 세미나
Amazon Web Services Korea
 

Tendances (20)

Aws Autoscaling
Aws AutoscalingAws Autoscaling
Aws Autoscaling
 
서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
서버리스 앱 배포 자동화 (김필중, AWS 솔루션즈 아키텍트) :: AWS DevDay2018
 
IAM Introduction
IAM IntroductionIAM Introduction
IAM Introduction
 
Amazon EC2 Deep Dive - 이창수 (AWS 솔루션 아키텍트) : 8월 온라인 세미나
Amazon EC2 Deep Dive - 이창수 (AWS 솔루션 아키텍트) : 8월 온라인 세미나Amazon EC2 Deep Dive - 이창수 (AWS 솔루션 아키텍트) : 8월 온라인 세미나
Amazon EC2 Deep Dive - 이창수 (AWS 솔루션 아키텍트) : 8월 온라인 세미나
 
(CMP201) All You Need To Know About Auto Scaling
(CMP201) All You Need To Know About Auto Scaling(CMP201) All You Need To Know About Auto Scaling
(CMP201) All You Need To Know About Auto Scaling
 
An Introduction to AWS
An Introduction to AWSAn Introduction to AWS
An Introduction to AWS
 
All You Need to Know about AWS Elastic Load Balancer
All You Need to Know about AWS Elastic Load BalancerAll You Need to Know about AWS Elastic Load Balancer
All You Need to Know about AWS Elastic Load Balancer
 
AWS Elastic Load Balancing for AWS Architect & SysOps Certification
AWS Elastic Load Balancing for AWS Architect & SysOps CertificationAWS Elastic Load Balancing for AWS Architect & SysOps Certification
AWS Elastic Load Balancing for AWS Architect & SysOps Certification
 
Introduction to Amazon EC2
Introduction to Amazon EC2Introduction to Amazon EC2
Introduction to Amazon EC2
 
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
 
Intro to AWS Lambda
Intro to AWS Lambda Intro to AWS Lambda
Intro to AWS Lambda
 
AWS IAM -- Notes of 20130403 Doc Version
AWS IAM -- Notes of 20130403 Doc VersionAWS IAM -- Notes of 20130403 Doc Version
AWS IAM -- Notes of 20130403 Doc Version
 
Auto scaling using Amazon Web Services ( AWS )
Auto scaling using Amazon Web Services ( AWS )Auto scaling using Amazon Web Services ( AWS )
Auto scaling using Amazon Web Services ( AWS )
 
AWS Cloud trail
AWS Cloud trailAWS Cloud trail
AWS Cloud trail
 
Introduction to Amazon EC2
Introduction to Amazon EC2Introduction to Amazon EC2
Introduction to Amazon EC2
 
Amazon S3 Masterclass
Amazon S3 MasterclassAmazon S3 Masterclass
Amazon S3 Masterclass
 
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 route 53
Aws route 53Aws route 53
Aws route 53
 
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
 
보안 사고 예방을 위한 주요 AWS 모범 사례 – 신은수, AWS 보안 담당 솔루션즈 아키텍트:: AWS 온라인 이벤트 – 클라우드 보안 특집
보안 사고 예방을 위한 주요 AWS 모범 사례 – 신은수, AWS 보안 담당 솔루션즈 아키텍트:: AWS 온라인 이벤트 – 클라우드 보안 특집보안 사고 예방을 위한 주요 AWS 모범 사례 – 신은수, AWS 보안 담당 솔루션즈 아키텍트:: AWS 온라인 이벤트 – 클라우드 보안 특집
보안 사고 예방을 위한 주요 AWS 모범 사례 – 신은수, AWS 보안 담당 솔루션즈 아키텍트:: AWS 온라인 이벤트 – 클라우드 보안 특집
 

En vedette

En vedette (8)

(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS(DVO401) Deep Dive into Blue/Green Deployments on AWS
(DVO401) Deep Dive into Blue/Green Deployments on AWS
 
Security & Compliance in AWS
Security & Compliance in AWSSecurity & Compliance in AWS
Security & Compliance in AWS
 
(SDD408) Amazon Route 53 Deep Dive: Delivering Resiliency, Minimizing Latency...
(SDD408) Amazon Route 53 Deep Dive: Delivering Resiliency, Minimizing Latency...(SDD408) Amazon Route 53 Deep Dive: Delivering Resiliency, Minimizing Latency...
(SDD408) Amazon Route 53 Deep Dive: Delivering Resiliency, Minimizing Latency...
 
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...
 
Advanced Approaches to Amazon VPC and Amazon Route 53 | AWS Public Sector Sum...
Advanced Approaches to Amazon VPC and Amazon Route 53 | AWS Public Sector Sum...Advanced Approaches to Amazon VPC and Amazon Route 53 | AWS Public Sector Sum...
Advanced Approaches to Amazon VPC and Amazon Route 53 | AWS Public Sector Sum...
 
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
 
C2S: What’s Next
C2S: What’s NextC2S: What’s Next
C2S: What’s Next
 
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
 

Similaire à Auto Scaling Groups

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
 

Similaire à Auto Scaling Groups (20)

AWS CloudFormation Best Practices
AWS CloudFormation Best PracticesAWS CloudFormation Best Practices
AWS CloudFormation Best Practices
 
Log Analytics with Amazon Elasticsearch Service - September Webinar Series
Log Analytics with Amazon Elasticsearch Service - September Webinar SeriesLog Analytics with Amazon Elasticsearch Service - September Webinar Series
Log Analytics with Amazon Elasticsearch Service - September Webinar Series
 
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
 
DevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office HoursDevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office Hours
 
AWS Infrastructure as Code - September 2016 Webinar Series
AWS Infrastructure as Code - September 2016 Webinar SeriesAWS Infrastructure as Code - September 2016 Webinar Series
AWS Infrastructure as Code - September 2016 Webinar Series
 
Deep Dive - Infrastructure as Code
Deep Dive - Infrastructure as CodeDeep Dive - Infrastructure as Code
Deep Dive - Infrastructure as Code
 
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
 
Automating your Infrastructure Deployment with CloudFormation and OpsWorks –...
 Automating your Infrastructure Deployment with CloudFormation and OpsWorks –... Automating your Infrastructure Deployment with CloudFormation and OpsWorks –...
Automating your Infrastructure Deployment with CloudFormation and OpsWorks –...
 
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDeployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
 
Automating your Infrastructure Deployment with AWS CloudFormation and AWS Ops...
Automating your Infrastructure Deployment with AWS CloudFormation and AWS Ops...Automating your Infrastructure Deployment with AWS CloudFormation and AWS Ops...
Automating your Infrastructure Deployment with AWS CloudFormation and AWS Ops...
 
Programando sua infraestrutura com o AWS CloudFormation
Programando sua infraestrutura com o AWS CloudFormationProgramando sua infraestrutura com o AWS CloudFormation
Programando sua infraestrutura com o AWS CloudFormation
 
Amazon Web Services Security
Amazon Web Services SecurityAmazon Web Services Security
Amazon Web Services Security
 
Automated Intrusion Detection and Response on AWS
Automated Intrusion Detection and Response on AWSAutomated Intrusion Detection and Response on AWS
Automated Intrusion Detection and Response on AWS
 
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and moreScaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
Scaling Drupal in AWS Using AutoScaling, Cloudformation, RDS and more
 
2013 05-openstack-israel-heat
2013 05-openstack-israel-heat2013 05-openstack-israel-heat
2013 05-openstack-israel-heat
 
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014(SEC303) Mastering Access Control Policies | AWS re:Invent 2014
(SEC303) Mastering Access Control Policies | AWS re:Invent 2014
 
Deep Dive: Infrastructure as Code
Deep Dive: Infrastructure as CodeDeep Dive: Infrastructure as Code
Deep Dive: Infrastructure as Code
 
Amazon ECS Deep Dive
Amazon ECS Deep DiveAmazon ECS Deep Dive
Amazon ECS Deep Dive
 
AWS CloudFormation Intrinsic Functions and Mappings
AWS CloudFormation Intrinsic Functions and Mappings AWS CloudFormation Intrinsic Functions and Mappings
AWS CloudFormation Intrinsic Functions and Mappings
 
Infrastructure as Code
Infrastructure as CodeInfrastructure as Code
Infrastructure as Code
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 

Auto Scaling Groups

  • 1. Auto Scaling Groups Advanced AWS meetup ! ! ! Peter Sankauskas Founder of CloudNative @pas256 https://cloudnative.io/ @pas256
  • 2. Daily life More users More instances More data More logs Higher costs New engineers Increased deployment frequency Reduce costs Boss Eliminate deployment risks Deadline https://cloudnative.io/ @pas256
  • 3. Your Goal Sleep Reliable Social life Sleep Uptime Time with family Sleep https://cloudnative.io/ @pas256
  • 4. “Don’t hate the Pager, hate the game” – PagerDuty https://cloudnative.io/ @pas256
  • 5. Old world Instances running 11 9 7 4 2 0 70% Wasted Used Capacity https://cloudnative.io/ @pas256
  • 6. Auto Scaling Group • Your assistant in the cloud • First level support • Automation 11 9 7 4 2 0 Used Capacity https://cloudnative.io/ @pas256
  • 7. Auto Scaling Group • Capacity: minimum, maximum, desired • Access: ELB • Polices • Where: • Availability Zones • VPC Subnets ASG Launch Config Scaling Policy Scaling Policy Scaling Policy Scheduled Scheduled Action Scheduled Action Action https://cloudnative.io/ @pas256
  • 8. {! "Type" : "AWS::AutoScaling::AutoScalingGroup",! "Properties" : {! "AvailabilityZones": [ String, ... ],! "Cooldown": String,! "DesiredCapacity": String,! "HealthCheckGracePeriod": Integer,! "HealthCheckType": String,! “LaunchConfigurationName": String,! "LoadBalancerNames": [ String, ... ],! "MaxSize": String,! "MetricsCollection": [ MetricsCollection, ... ]! "MinSize": String,! “NotificationConfiguration": NotificationConfiguration,! "PlacementGroup": String,! "Tags": [ Auto Scaling Tag, ... ],! “TerminationPolicies": [ String, ... ],! "VPCZoneIdentifier": [ String, ... ]! }! } https://cloudnative.io/ @pas256
  • 9. Launch Configuration • Every ASG needs a Launch Configuration • Describes what an individual EC2 instance looks like • AMI • Instance type • Security groups https://cloudnative.io/ @pas256
  • 10. {! "Type" : "AWS::AutoScaling::LaunchConfiguration",! "Properties" : {! "AssociatePublicIpAddress": Boolean,! "BlockDeviceMappings": [ BlockDeviceMapping, ... ],! "EbsOptimized": Boolean,! "IamInstanceProfile": String,! "ImageId": String,! "InstanceMonitoring": Boolean,! "InstanceType": String,! "KernelId": String,! "KeyName": String,! "RamDiskId": String,! "SecurityGroups": [ SecurityGroup, ... ],! "SpotPrice": String,! "UserData": String! }! } https://cloudnative.io/ @pas256
  • 11. Scaling Plans 1. Fixed 2. Manual 3. Scheduled 4. Dynamic https://cloudnative.io/ @pas256
  • 12. Fixed • Ensure a fixed number of instances is always running • Set MinSize = MaxSize • Examples • Any “master” service • Zookeeper - 3 nodes across 3 AZs • Cassandra 3 2 1 0 Used Capacity https://cloudnative.io/ @pas256
  • 13. # One Asgard instance - troposphere example! launchConfig = t.add_resource(asg.LaunchConfiguration("launchConf",! AssociatePublicIpAddress=True,! IamInstanceProfile=Ref(asgardInstanceProfile),! ImageId=FindInMap("AWSRegion2AMI", Ref("AWS::Region"), "AMI"),! InstanceType="m3.medium",! KeyName="admin",! SecurityGroups=[Ref(asgardInstanceSecurityGroup)],! ))! ! asgardASG = t.add_resource(asg.AutoScalingGroup("asgardASG",! Tags=[asg.Tag("Name", "Asgard", True)],! Cooldown="120",! MinSize="1",! MaxSize="1",! AvailabilityZones=["us-west-2a","us-west-2b"],! VPCZoneIdentifier=["subnet-c46c6982","subnet-8133f6e4"],! LaunchConfigurationName=Ref(asgardLaunchConfig),! )) https://cloudnative.io/ @pas256
  • 14. Manual Scaling • Use API to change capacity on demand SetDesiredCapacity! • AutoScalingGroupName = my-asg • DesiredCapacity = 2 2 1 0 Used Capacity https://cloudnative.io/ @pas256
  • 15. Scheduled • At this time, set capacity to X • Each ScheduledAction must have a unique start time • Guaranteed order of execution within same ASG 11 9 7 4 2 0 Used Capacity https://cloudnative.io/ @pas256
  • 16. Specific date and time PutScheduledUpdateGroupAction! • ScheduledActionName = ScaleOut • AutoScalingGroupName = my-asg • DesiredCapacity = 3 • StartTime = “2013-05-12T08:00:00Z” https://cloudnative.io/ @pas256
  • 17. Recurring schedule PutScheduledUpdateGroupAction! • ScheduledActionName = Scaleout-schedule-year • AutoScalingGroupName = my-asg • DesiredCapacity = 3 • Recurrence = “30 0 1 1,6,12 0” https://cloudnative.io/ @pas256
  • 18. Dynamic Scaling • Best Utilization • Lowest Cost 11 9 7 4 2 0 Used Capacity https://cloudnative.io/ @pas256
  • 19. Trigger: CloudWatch Alarm • Metrics • CPU Utilization • Network in/out • Size of queue (SQS) • Anything you put into CloudWatch • Set the Alarm Action to the ARN of the ScalingPolicy https://cloudnative.io/ @pas256
  • 20. Action: ScalingPolicy • Adjustment Types • Change by number • E.g. Scale Out: Add 2 more instances • E.g. Scale In: Remove 1 instances • Exact • E.g. Scale Out: Have exactly 8 instances • Percentage • E.g. Scale Out: Add 25% more instances https://cloudnative.io/ @pas256
  • 21. Cooldown • After a ScalingPolicy has been fired, wait X seconds before performing any other actions. • Manual Scaling: SetDesiredCapacity • HonorCoolDown = True/False https://cloudnative.io/ @pas256
  • 22. Load Balancing • Put an ELB in front of the instance in your ASG • Set when creating the ASG • Zero effort in adding and removing instances • Additional health check options https://cloudnative.io/ @pas256
  • 23. Health Checks • By default, ASG uses EC2 Status Checks • If you have an ELB, you can use the same ELB health checks • HTTP:80/healthcheck! • HTTP 200 response is the only thing that is considered healthy • E.g. Return something else while app is loading filled https://cloudnative.io/ @pas256
  • 24. Termination Policy • OldestInstance • NewestInstance • OldestLaunchConfiguration • ClosestToNextInstanceHour https://cloudnative.io/ @pas256
  • 26. Requirements for Dynamic Scaling • Stateless application • Configuration must be 100% automated • Tools understand dynamic environments • Config management • Monitoring • Log aggregation https://cloudnative.io/ @pas256
  • 28. Migration • Create an ASG or LaunchConfiguration from an already running instance • Put that instance in the ASG https://cloudnative.io/ @pas256
  • 29. {! "Type" : "AWS::AutoScaling::AutoScalingGroup",! "Properties" : {! "AvailabilityZones" : [ String, ... ],! "Cooldown" : String,! "DesiredCapacity" : String,! "HealthCheckGracePeriod" : Integer,! "HealthCheckType" : String,! "InstanceId" : String,! "LaunchConfigurationName" : String,! "LoadBalancerNames" : [ String, ... ],! "MaxSize" : String,! "MetricsCollection" : [ MetricsCollection, ... ]! "MinSize" : String,! "NotificationConfiguration" : NotificationConfiguration,! "PlacementGroup" : String,! "Tags" : [ Auto Scaling Tag, ... ],! "TerminationPolicies" : [ String, ... ],! "VPCZoneIdentifier" : [ String, ... ]! }! } https://cloudnative.io/ @pas256
  • 30. {! "Type" : "AWS::AutoScaling::LaunchConfiguration",! "Properties" : {! "AssociatePublicIpAddress" : Boolean,! "BlockDeviceMappings" : [ BlockDeviceMapping, ... ],! "EbsOptimized" : Boolean,! "IamInstanceProfile" : String,! "ImageId" : String,! "InstanceId" : String,! "InstanceMonitoring" : Boolean,! "InstanceType" : String,! "KernelId" : String,! "KeyName" : String,! "RamDiskId" : String,! "SecurityGroups" : [ SecurityGroup, ... ],! "SpotPrice" : String,! "UserData" : String! }! } https://cloudnative.io/ @pas256
  • 31. # Instance Configuration - Self healing NAT - troposphere! natLaunchConfig = t.add_resource(asg.LaunchConfiguration(! "natLaunchConfig",! AssociatePublicIpAddress=True,! InstanceType="t1.micro",! ImageId="ami-f032acc0",! SecurityGroups=[Ref(natSecurityGroup)],! IamInstanceProfile=Ref(natInstanceProfile),! UserData=Base64(Join("n", [! "#!/bin/bash",! "yum update -y",! "instanceId=`/opt/aws/bin/ec2-metadata -i | cut -f2 -d' '`",! "region=`/opt/aws/bin/ec2-metadata -z | cut -f2 -d' ' | sed '$s/.$//'`",! "vpcId=`aws ec2 describe-instances --instance-ids $instanceId --region $region --query 'Reservations[*].Instances[*].VpcId' --output text`",! """rtbId=`aws ec2 describe-route-tables --region $region --filters "[{"Name":"vpc-id"," Values":["$vpcId"]},{"Name":"association.main","Values":["true "]}]" --query RouteTables[*].RouteTableId --output text`""",! """aws ec2 modify-instance-attribute --instance-id $instanceId --source-dest-check '{"Value": false}' --region $region --output table""",! "aws ec2 replace-route --route-table-id $rtbId --destination-cidr-block 0.0.0.0/0 -- instance-id $instanceId --region $region --output table",! "aws ec2 create-route --route-table-id $rtbId --destination-cidr-block 0.0.0.0/0 -- instance-id $instanceId --region $region --output table"! ]))! )) https://cloudnative.io/ @pas256
  • 32. UserData and cloud-init • Inside LaunchConfiguration • Set UserData script to be run by cloud-init • If you are using Chef, this is what you will do • More details: • Watch Episode #4 on Answers for AWS https://cloudnative.io/ @pas256
  • 33. Baking AMIs • Raw: Do everything on boot • Fully Baked: Immutable infrastructure • Half-Baked: Anything in-between ! http://answersforaws.com/blog/2013/11/half-baked/ https://cloudnative.io/ @pas256
  • 34. Deploy Changes • Option 1: Change AMI or User Data in LaunchConfiguration • NOTE: This has no immediate outcome • Only affects newly launched instances • Revisit TerminatePolicy • You need to terminate existing instances so that new ones come up with the changes https://cloudnative.io/ @pas256
  • 35. Deploy Changes • Option 2: Create a completely new stack • Use CloudFormation (or whatever) to create a new ASG, LaunchConfig, ScalingPolicies, ELB, Security Group, VPC, Subnets, etc • Overkill • If you have high traffic, the new ELB will not be pre-scaled and will not handle the load • Need to contact AWS TAM https://cloudnative.io/ @pas256
  • 36. Blue/Green Deployment Or is a red/black deployment… or is it A/B deployment? • Option 3: • Reuse existing infrastructure including the same ELB • Create a new ASG and LaunchConfig • Switch traffic at the ELB from old ASG to new ASG https://cloudnative.io/ @pas256
  • 38. “It’s not about how fast you can deploy, it is about how fast you can rollback” – Peter Sankauskas… just now https://cloudnative.io/ @pas256
  • 39. Canary Deployment • Very similar to blue/green deployment • New ASG and LaunchConfig • Add traffic to only 1 instance in the new ASG • Then 2 instance • Up to 100% • Both versions running side by side • Roll off traffic from old ASG instances https://cloudnative.io/ @pas256
  • 40. Running multiple version • DB Schema changes are on a different schedule to code deployments • mcfunley (Etsy): “We deploy schema changes once per week. The code always works against both versions of the schema. We never take downtime for schema changes. We avoid data loss by doing soft deletes as much as we can.” • Deploy features dark • Use Feature Flags https://cloudnative.io/ @pas256
  • 41. Tools • Baking AMIs • Packer - Hashicorp • Aminator - Netflix • CloudNative • Deployment • Asgard - Netflix • CloudNative https://cloudnative.io/ @pas256
  • 42. New World • Automation expert • Stateless, independently scalable apps • Allergic to manual labor • Embrace your laziness • Auto Scaling Groups provide: • Zero-effort scaling • Fault-tolerance • Increase reliability & uptime • Decrease cost https://cloudnative.io/ @pas256