从EC2实例中查找区域 [英] Find region from within EC2 instance

查看:135
本文介绍了从EC2实例中查找区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来查找一个实例的区域从实例中?

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

我在寻找类似的方法<一个东西href="http://stackoverflow.com/questions/625644/find-out-the-instance-id-from-within-an-ec2-machine">finding实例ID 。

推荐答案

这URL(http://169.254.169.254/latest/dynamic/instance-identity/document)似乎并没有工作了。我收到了404,当我试图使用它。我有以下的code,这似乎工作,虽然:

That URL (http://169.254.169.254/latest/dynamic/instance-identity/document) doesn't appear to work anymore. I get a 404 when I tried to use it. I have the following code which seems to work though:

EC2_AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"

希望这有助于。

Hope this helps.

这篇关于从EC2实例中查找区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆