从 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屋!
查看全文