简体   繁体   中英

How should I configure an AWS Auto-Scalling Group mixed_instances_policy to only allow for spot_instances with multiple EC2 instance_types?

I have an AWS Auto-Scalling Group that spawns (or shuts down) one EC2 machine based on the amount of messages in a specific SQS Queue. That works as expected, but sometimes I get the following error:

Launching a new EC2 instance. Status Reason: Could not launch Spot Instances. InsufficientInstanceCapacity - There is no Spot capacity available that matches your request. Launching EC2 instance failed.

A DevOps guy I know told me to " increase the amount of spot_instance_pools to 20 and add some more instance_types ".

I did some research and found that the default number of spot_instance_pools is 2 . That same number is shown on AWS Console. Whenever I have this problem, I deploy a new script changing the EC instance type and it works, so both those suggestions seems like a valid ones to me.

The problem is that my current Terraform script does not have the enclosing mixed_instances_policy and I'm unsure how to configure it to keep only on_spot instances (since they are cheaper) and no on_demand instances. So far I have come up with:

  mixed_instances_policy = {
    on_demand_percentage_above_base_capacity = 0
    spot_instance_pools                      = 20   
  }

Keeping the other values inside mixed_instances_policy with the defaults should suffice for me.

But I did not understand how to configure the mixed_instances_policy launch_template . Is it nested within mixed_instances_policy ? Should I add a mixed_instances_policy launch_template override too? Or perhaps a launch_template_specification

TL;DR;

How do I configure an AWS Auto-Scalling Group mixed_instances_policy to only allow for spot_instances with multiple EC2 instance_types?

The on_demand_percentage_above_base_capacity = 0 line is the one you want. Based on the doc you shared and the structure in the AWS doc , I'd say it probably goes inside instances_distribution That tells the ASG to launch 0% on demand (aka 100% spot). Within the mixed_instances_policy you need to add overrides for the instance types you're adding (weights are optional. Weight is the number of desired capacity units that instance type counts as).

Also, the number of spot pools doesn't mater much for your use case. That's saying /if everything is available/ launch up to that many different spot types per AZ. Having more pools does help a bit with availability though, because if one pool becomes supply constrained, then you won't have all your instances terminated at once, but it doesn't impact being able to launch at all.

Actually, if you want cheaper cost, you want the number lower. Because if you have allocation strategy as 'cheapest first' then you want few pools per AZ (since its only the cheapest few pools then). If there's only 1 instance type available in the AZ, its going to launch that one regardless. So the number of overrides you select is the important part to maintain availability when launching.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM