0

I want to write a script which uses the AWS api within an EC2 instance to modify its own configuration, however to use the aws command I need to provide a AWS_DEFAULT_REGION environment variable with the correct region (i.e. 'us-east-1').

If I simply want to issue command pertaining to the instance itself, how can I discover which region to use without hard-coding it in? I looked through the instance metadata documentation and couldn't find a solution.

mikegreiling
  • 1,160
  • 12
  • 21

1 Answers1

0

The closest I've been able to find is using the following instance metadata query:

$ curl http://169.254.169.254/latest/meta-data/placement/availability-zone/
us-east-1a

then just shave off the letter at the end to get the region.

mikegreiling
  • 1,160
  • 12
  • 21