How to place spot instances in the cheapest AZ without hard-coding it or writing complex logic?

0

One of my regions has a specific AZ that's consistently almost 50% cheaper than the others, for my instance type. Yet my placement strategy consistently picks one of the more expensive AZs. Here's the relevant code snippet:

			InstancesDistribution: &awsautoscaling.InstancesDistribution{
				SpotAllocationStrategy:              awsautoscaling.SpotAllocationStrategy_LOWEST_PRICE,
				OnDemandAllocationStrategy:          awsautoscaling.OnDemandAllocationStrategy_LOWEST_PRICE,
				OnDemandBaseCapacity:                jsii.Number(0),
				OnDemandPercentageAboveBaseCapacity: jsii.Number(0),
				SpotInstancePools:                   jsii.Number(2),
			},

Is there a simple configuration fix for this? I'd like to avoid having to write a complicated Lambda to figure out the lowest price and dynamically change configurations.

1 Answer
0

Based on your snippit and tags on this question, I assume you're talking about launching Spot instances in an ASG?

Currently there's no way to do what you're asking. The ASG will always first try to balance work across all available AZs. However, the AutoScaling team is always working on new options to meet usecases that aren't currently possible, so I've passed on this feedback to them for future feature decisions.

Currently you have 3 options

  • Leave it as-is, and let ASG launch across all the AZs
  • Lambda functions, as you suggested (periodically checking prices and swapping the single AZ for the ASG) - note that this is much more likely to have availability issues from launch failures
  • Create 2 ASGs; 1 in your preferred AZ and another with all the other regions AZs enabled in it. Set the scaling metrics such that the "Primary" ASG scales first. This could lead to a bit of oscillation/churn between ASGs, especially if its a smaller environment and/or the metric is spiky
  • directly launch capacity via aws ec2 create-fleet instead of using an ASG (but, you'll lose out on all the other ASG features if you do this)

Remember that Spot prices can and will change over time, so even if that 1 AZ has been cheaper in the short/medium term doesn't mean it'll always be that way, or that it'll have enough Spot capacity to consistently meet your needs

AWS
EXPERT
answered 2 months ago
  • Hi Shahad, your analysis is correct, and I forgot to mention it's an ASG with only 1 instance. It's serving as capacity provider for ECS. I don't understand the suggested "2 ASGs" architecture, would this work with ECS?. Also I'm not sure EC2 Fleet will work as an ECS Capacity Provider. So I'll have to create a Lambda to change the target type and monitor for availability issues. I have been watching this region and for the past several months the prices have been the same, with one AZ consistently cheaper. If I wanted to have availability guarantees, I would use one of the other spot strategy options or even an On-demand or Reserved instance. I'm quite disappointed that LOWEST_PRICE does not mean LOWEST_PRICE -- this would be the best feedback you can provide to the responsible team.

  • Ahh, I assumed this was a larger environment. The 2 ASGs option would be for if you had more instances (would work best with at least a couple dozen). In general it would still work with ECS, but likely not with a single instance type. And you're correct, Capacity Providers specifically are designed to work with an ASG. I've passed on your feedback that you'd like it to be "Lowest price for the region" vs "Lowest price for the AZ the ASG selects". Thank you very much for taking the time to provide these details around your usecase

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions