3
votes

I'm writing a service which programmatically starts EC2 instances on demand. I want to give it the best chance of being able to start an instance at any time, minimizing fails due to lack of capacity. It doesn't matter what availability zone the instances run in within a region, just that I have the best chance of starting one.

I'm wondering, if I don't specify a placement object when using the runInstances method of the api, will it:

A) Run my new instances in any availability zone which has the capacity available

B) Randomly pick an availability zone and fail if there isn't any spare capacity there

C) Something else

My research shows people believing it's A) or B) but I can't find a definitive answer from aws.

If it's A) I guess I can make one call and leave it to aws to figure out if I can have the instance. If it's B) I guess I should pass in the availability zone and keep trying them all until I find one with spare capacity.

Thanks.

1

1 Answers

2
votes

Looks like Launching Instances in a Specific Availability Zone provides an answer:

When you launch an instance, you can optionally specify an Availability Zone. If you do not specify an Availability Zone, Amazon EC2 selects one for you in the region that you are using. When launching your initial instances, we recommend accepting the default Availability Zone, which enables us to select the best Availability Zone for you based on system health and available capacity. [...]

Although the language isn't 100% precise I take from this that my option A) is correct & not specifying an availability zone means Amazon EC2 will try it's best to find a zone with available capacity, although possibly applying some other criteria first.