Find region from within an EC2 instance

前端 未结 28 1506
谎友^
谎友^ 2020-12-02 06:24

Is there a way to look up the region of an instance from within the instance?

I\'m looking for something similar to the method of finding the instance id.

28条回答
  •  无人及你
    2020-12-02 07:03

    Was also looking for a solution to find region from the instance and here is my pure Bash solution:

    az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
    region=${az:0:${#az}-1}
    

    unless there are regions where AZ has more than two letters, which I'm not aware of.

提交回复
热议问题