[cs615asa] HW2 Required Arguments

Jan Schaumann jschauma at stevens.edu
Mon Feb 17 22:07:54 EST 2020


Ritvik Tiwari <rtiwari2 at stevens.edu> wrote:
 
> While handling availability zone, can we safely
> assume that the region in .aws/config and the
> availability zone of the volume I'd entered by the
> user match?

No, that is not a safe assumption.  A user may have
created a volume in any availability zone besides the
one they may or may not have set as the default in
their configuration file.

> Since the aws describe-volumes will throw up a
> volume not found error otherwise.

You can iterate over the regions to find the region
and availability zone of an instance.  Sample shell
code:

for region in $(aws ec2 describe-regions | jq -r '.Regions[].RegionName'); do
        az="$(aws ec2 describe-volumes --region "${region}" --volume-id "${volumeID}" 2>/dev/null | jq -r '.Volumes[].AvailabilityZone')"
        if [ x"${az}" != x"" ]; then
                echo Volume "${volumeID}" is in region "${region}", availabiliy-zone "${az}"
        fi
done

This is obviously slow; you may choose to first query
with the default region to avoid long wait times when
most likely the volume is in the default region.

-Jan


More information about the cs615asa mailing list