How to get the availability zone details for a running instance
I am iterating through the running instance list returned by DescribeInstances API. I would like to know how can I retriev开发者_C百科e the availability zone for each of these instances.
The availability zone can be accessed with:
instance.getPlacement().getAvailabilityZone();
Surprised no one has posted this yet, which is the best, fastest, and easiest way to do this AFAIK.
curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone
You cannot get the availability zone details for a running instance until those instances have connected with ELASTIC LOAD BALANCER (target groups).
There is no API for this:
I did it as follows: 1. Use API to get the current available zones. 2. Loop through the returned zones, set filter on DescribeInstances foreach of these and get the instance details.
精彩评论