从EC2实例中查找区域 [英] Find region from within an EC2 instance
本文介绍了从EC2实例中查找区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从实例中查找实例的区域?
Is there a way to look up the region of an instance from within the instance?
我正在寻找与找到实例ID 。
推荐答案
该URL( http://169.254.169.254/latest/dynamic/instance-identity/document )似乎不再起作用。尝试使用时会收到404。我有以下似乎可以运行的代码:
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 's/[a-z]$//'`"
希望这会有所帮助。
编辑:已改进 sed
根据评论
这篇关于从EC2实例中查找区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文