Find region from within an EC2 instance

前端 未结 28 1512
谎友^
谎友^ 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:05

    At some point since most of these answers have been posted, AWS did the reasonable thing and implemented a new path: latest/meta-data/placement/region.

    This means getting the region should be as simple as

    REGION="$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/region)"
    

    EDIT: It's also probably worth mentioning that this endpoint was made available in the 2019-10-01 release of the metadata API. Make sure your instance supports that version or later before using this by checking http://169.254.169.254/.

提交回复
热议问题