尝试从其中检索EC2实例ID元数据时超时 [英] Timeout when trying to retrieve EC2 instance-id metadata from within it

查看:73
本文介绍了尝试从其中检索EC2实例ID元数据时超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在启动Windows 10 EC2实例,并尝试使用以下命令从CMD中检索它的实例ID:

I'm launching a Windows 10 EC2 instance and trying to retrieve it's instance-id from the CMD with the command:

curl http://169.254.169.254/latest/meta-data/instance-id

此操作一直持续到昨天,但现在每次都失败,从而引发超时错误.

This worked until yesterday, but now it fails every time, raising a Timeout error.

curl: (7) Failed to connect to 169.254.169.254 port 80: Timed out

我查阅了aws有关检索EC2元数据的文档,但未发现有关检索尝试的到期时间的任何信息.另外,我尝试从实例创建AMI,然后基于该AMI启动新实例,以尝试某种刷新"可能的到期时间,但没有成功.

I've looked up aws's documentation about retrieving EC2 metadata and didn't found anything regarding an expiration time for the retrieving attempt. Also, I've tried to create an AMI from my instance and launch a new instance based on this AMI to try some sort of "refresh" of a possible expiration time, and it didn't worked.

我已经在IAM角色中搜索了与检索元数据权限有关的内容,但似乎没有什么适合我的问题.

I've searched within the IAM Roles for something related to retrieving metadata permission, but nothing seems to fit my issue.

我还尝试了在这里,但没有什么东西足以解决我的问题.

I've also tried the answers from here but nothing was specific enough to my problem.

可能会发生什么?这连续工作了大约两个月,然后突然停止了工作.

What could have happened? This worked for about two months straight and suddenly it stopped working.

关于类似问题的另一篇帖子得到了答案解决了我的问题.

Another post, regarding a similar problem, got an answer that fixed my problem.

我只运行了 C:\ ProgramData \ Amazon \ EC2-Windows \ Launch \ Scripts \ InitializeInstance.ps1 ,脚本便应用了新生儿EC2 Windows实例的默认规范.我仍然不知道为什么会发生此问题,但是此解决方案适用于对配置规范没有任何要求的人.

I simply ran C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 and the script applied the default specifications of a newborn EC2 windows instance. I still don't know why this problem happened, but this solution works for someone that doesn't have anything to loose on configuration specifications.

推荐答案

从您共享的解决方法来看,似乎无法获取实例ID的原因似乎是由于实例路由配置错误.要从元数据中检索实例ID,路由169.254.169.254必须指向实例的正确网关.当您尝试从与创建AMI的父实例不同的子网中的自定义AMI启动实例时,Windows Server 2016或更高版本通常会出现此问题.

From the workaround that you shared, it seems the reason why you were not able to get the Instance ID was somehow the routes for your Instance got misconfigured. To retrieve Instance ID from the metadata, the route 169.254.169.254 must point to the right gateway of the Instance. This problem generally occurs with Windows Server 2016 or above when you try to launch an Instance from a custom AMI, in a subnet which is different from the parent Instance from which the AMI was created.

当您运行命令时,它计划了InitializeInstance.ps1脚本,并在下次启动时重新配置了路由.

When you ran the command, it scheduled the InitializeInstance.ps1 script, and during the next boot it re-configured the routes.

以后,如果您发现任何此类问题,请确保IP 169.254.169.254指向正确的网关,如果您发现路由是正确的,则可以使用命令ipconfig/all和route print命令进行检查.如果配置错误,则可以使用带有适当参数的route delete和route add命令来使路由正确,或者简单地调度InitializeInstance.ps1脚本,该脚本将在实例下次启动时更正路由.

In, future if you see any such issue, make sure the IP 169.254.169.254 is pointing to the correct gateway, which you can check using the command ipconfig /all and route print commands, in case you find that the routes are mis-configured, you can use the route delete and route add commands with proper parameters to make the routes correct or simply schedule the InitializeInstance.ps1 script, which will correct the routes when the Instance boots up the next time.

请参考: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2launch.html

这篇关于尝试从其中检索EC2实例ID元数据时超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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