Combining On-Demand and Spot Instances for Auto Scaling Group in AWS

Implementing On-Demand and Spot Instances for Auto Scaling Group

Prev Question Next Question

Question

You are a DevOps engineer working in a small IT company.

It has a limited operation budget for AWS resources.

So spot EC2 instances are always suggested.

There is a new application that will be deployed via a Load Balancer and Auto Scaling Group.

However, as this application controls the authentication for all other company products, it is inappropriate to use only spot instances for this.

The best way is to use a combination of On-Demand and Spot instances for the Auto Scaling Group if possible.

What is the best way to implement this?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Correct Answer - B.

There are two methods to configure an Auto Scaling Group - a Launch Configuration or a Launch Template.

Please refer to https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg-launch-template.html and https://docs.aws.amazon.com/autoscaling/ec2/userguide/create-asg.html for details:

Option A is incorrect: Although this can potentially work, it is not the best approach compared to option.

B.

It also needs to maintain two ASGs.

Option B is CORRECT: To create an ASG by a Launch Template, users can have the flexibility to launch a combination of instance types and On-Demand and Spot purchase options.

Option C is incorrect: Because Launch Configuration does not support the combinations of On-Demand and Spot purchase options.

Option D is incorrect: Refer to Option.

B.

Edit action

Action name
Choose a name for your action

No more than 100 characters

‘Action provider
AWS Lambda v|
Region
Asia Pacific (Sydney) v ]

Input artifacts
Choose an input artifact for this action, Learn more [2

Add

No more than 100 characters

Function name
Choose a function that you have already created in the AWS Lambda console. Or create a function in the Amazon Lambda console and then return to this task.

Q

This string will be used in the event data parameter passed to the handler in AWS Lambda.

Variable namespace - optional
Choose a namespace for the output variables from this action. You must choose @ namespace if you want to use the variables ths action produces in your configuration. Learn more (2

Output artifacts
Choose a name for the output ofthis action

‘Add

No more than 100 characters

The best way to implement a combination of On-Demand and Spot instances for the Auto Scaling Group is by using a Launch Template and configuring the On-Demand/Spot percentage accordingly. Option B is the correct answer.

A Launch Template is a resource that contains the configuration information to launch instances. It enables you to standardize and automate instance launches across multiple use cases. With a Launch Template, you can define the instance type, AMI, security group, network settings, and other parameters for launching instances.

To use a combination of On-Demand and Spot instances in an Auto Scaling Group with a Launch Template, you need to specify the instance allocation strategy in the template. The instance allocation strategy determines the mix of On-Demand and Spot instances that the Auto Scaling group launches.

To create a Launch Template with a mix of On-Demand and Spot instances, you need to:

  1. Create a Launch Template with the desired instance configuration, such as the AMI, instance type, security group, and other parameters.

  2. Specify the instance allocation strategy in the Launch Template. You can do this by setting the "InstanceMarketOptions" parameter in the Launch Template.

    • To specify a percentage of On-Demand instances, set the "SpotOptions" parameter to "null" and set the "OnDemandPercentageAboveBaseCapacity" parameter to the desired percentage. For example, to use 50% On-Demand instances, set "OnDemandPercentageAboveBaseCapacity" to 50.

    • To specify a percentage of Spot instances, set the "OnDemandOptions" parameter to "null" and set the "SpotAllocationStrategy" parameter to "capacity-optimized" or "lowest-price". Then set the "SpotInstancePools" parameter to the desired number of Spot pools. For example, to use 50% Spot instances, set "SpotAllocationStrategy" to "capacity-optimized" and "SpotInstancePools" to 2.

  3. Create an Auto Scaling group using the Launch Template. When you create the Auto Scaling group, it will launch instances according to the instance allocation strategy defined in the Launch Template.

In summary, to implement a combination of On-Demand and Spot instances for an Auto Scaling group, use a Launch Template with an instance allocation strategy that specifies the desired mix of On-Demand and Spot instances.