See how many aws instances are in each availability zone

590 Views Asked by At

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.

3

There are 3 best solutions below

0
On

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

0
On

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>
0
On

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'