user578086
user578086

Reputation: 331

See how many aws instances are in each availability zone

Is there a way to see how many instances are in a availability zone for AWS? I want to use the runInstances api to bring up instances but call it on the least loaded zone which I don't see a obvious solution to. Thanks.

Upvotes: 1

Views: 815

Answers (3)

Zioalex
Zioalex

Reputation: 4303

I had the same problem. I solved it using aws cli:

aws cloudformation describe-stack-resources --stack-name STACKNAME\ 
--output text | grep 'AWS::AutoScaling::AutoScalingGroup' | cut -f3 > /tmp/tmpfile

ASGNAME="`cat /tmp/tmpfile`"

aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names $ASGNAME \
--output text | egrep -e 'INSTANCES.*InService'

Upvotes: 0

Michael - sqlbot
Michael - sqlbot

Reputation: 179114

The obvious solution seems like it would be to call DescribeInstances and use the availability-zone filter to request the details of instances in each zone you want to check and count the instances returned in the response.

Or don't use the filter, which will get all of them for the region, then examine the records to see where each of them is, since that information is all returned in the response.

   <instancesSet>
      <item>
        <instanceId>i-1a2b3c4d</instanceId>
        ...
        <placement>
          <availabilityZone>us-west-2a</availabilityZone>
          <groupName/>
          <tenancy>default</tenancy>
        </placement>

Upvotes: 0

BrianJakovich
BrianJakovich

Reputation: 1614

As far as i know there's no way to check the amount of instances in an AZ. What you could do is use an Autoscaling group and specify the AZs that you want when creating it. Autoscaling will then disperse the instance load evenly amongst listed AZs

AZ = Availability zone

Upvotes: 1

Related Questions