Amazon EC2 Auto Scaling helps you maintain application availability and allows you to dynamically scale your Amazon EC2 capacity up or down automatically according to conditions you define. You can use Amazon EC2 Auto Scaling for fleet management of EC2 instances to help maintain the health and availability of your fleet and ensure that you are running your desired number of Amazon EC2 instances. You can also use Amazon EC2 Auto Scaling for dynamic scaling of EC2 instances in order to automatically increase the number of Amazon EC2 instances during demand spikes to maintain performance and decrease capacity during lulls to reduce costs. Amazon EC2 Auto Scaling is well suited both to applications that have stable demand patterns or that experience hourly, daily, or weekly variability in usage.
1. Edit asg.json update the values of the Target Group created on the previous step, as well as the subnets created by the CloudFormation template..
sed -i.bak -e "s#%TargetGroupARN%#$tg_arn#g" -e "s#%publicSubnet1%#$publicSubnet1#g" -e "s#%publicSubnet2%#$publicSubnet2#g" asg.json
The EC2 Auto Scaling group that you are going to deploy supports multiple purchase options (On-Demand and Spot Instances) and EC2 instance types.
Examining the asg.json configuration file, can you determine what would be the different configuration options in the deployed ASG?
How many On-Demand and Spot Instances would be deployed?
Which On-Demand and Spot Instances would be selected from the list of Overrides, and why?
Hint: take a look at the API reference for
InstancesDistribution to understand the different parameters in the asg.json configuration file.
OnDemandBaseCapacity of 2,
OnDemandPercentageAboveBaseCapacity of 0, and
DesiredCapacity of 4, initially the ASG is going to contain 2 On-Demand instances and 2 Spot Instances.
The lowest priced Spot Instances per AZ will be deployed. With the
SpotInstancePools of 4, once the desired capacity will be higher, the 4 lowest priced Spot Instance types from the list of Overrides will be selected to be deployed in each Availability Zone.
2. Create the auto scaling group by running:
aws autoscaling create-auto-scaling-group --cli-input-json file://asg.json
This command will not return any output if it is successful.
3. Browse to the Auto Scaling console and check out your newly created Auto Scaling group. Go to the EC2 Instances console and check how many On-Demand instances and how many Spot Instances were deployed - you can do so by using the filter option and selecting Lifecycle = Normal or Spot.
Since you deployed one Spot Instance in each Availability Zone, can you verify that the Auto Scaling group selected the lowest-priced Spot Instance in each Availability Zone?
Hint: Use the Spot Instance Pricing History tool
Example of the Spot Price History tool in the EC2 Spot console, showing the current Spot price for m5.large in the eu-west-1 region.