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
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
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
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
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
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
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