Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Created September 6, 2017 18:21
Show Gist options
  • Save bitdivine/3ba095a791e914d19388919485867b17 to your computer and use it in GitHub Desktop.
Save bitdivine/3ba095a791e914d19388919485867b17 to your computer and use it in GitHub Desktop.
Get the AWS region - either from the profile or, if running on an AWS instance, by looking up the instance metadata.
echo If the region is given in the environment:
echo $AWS_DEFAULT_REGION
echo If aws has been configured:
aws configure get region
echo If running on an aws instance, the availability zone is in the metadata and hence we have the region:
ec2metadata --availability-zone | sed -r 's/.$//g'
echo Equivalently:
curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -r 's/.$//g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment