athavan kanapuli
athavan kanapuli

Reputation: 492

Get AWS Availability zone info inside a machine

Is there an AWS API to hit and get the availability zone of the current machine where the code is running? I tried to check if such ENV variable is set automatically by AWS but couldn't find such a thing. Any help would be appreciated.

Upvotes: 0

Views: 140

Answers (1)

Marcin
Marcin

Reputation: 238249

You can get the current AZ of the instance using Instance metadata.

For example:

AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)

echo ${AZ}

will output (example):

us-east-1e

Upvotes: 2

Related Questions