Find region from within an EC2 instance

前端 未结 28 1429
谎友^
谎友^ 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 06:53

    2 liner that works as long as you are using ec2.internal as your search domain:

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

提交回复
热议问题