EC2 http://169.254.169.254/latest/user-data返回404

时间:2017-08-03 06:37:45

标签: amazon-web-services

尝试从win EC2实例中获取EC2 userdata

http://169.254.169.254/latest/user-data

我收到404 - 未找到错误

4 个答案:

答案 0 :(得分:0)

我也看到了这一点:

root@ip-172-31-29-121:/var/lib/cloud# curl http://169.254.169.254/latest/
dynamic
meta-data
user-dataroot@ip-172-31-29-121:/var/lib/cloud#
root@ip-172-31-29-121:/var/lib/cloud# curl http://169.254.169.254/latest/user-data
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">    
 <head>
  <title>404 - Not Found</title>
 </head>
 <body>
  <h1>404 - Not Found</h1>
 </body>
</html>

请注意,第一个curl命令表示数据应该在那里。

答案 1 :(得分:0)

我相信您正在遇到这种情况,因为您没有附加EC2用户数据

我在AWS控制台中进行了一项实验。我基于Ubuntu 18.04映像启动了两个相同的EC2实例。但是,在其中一个实例中,我附加了用户数据,而另一个实例中却没有

具有用户数据的实例

$ curl http://169.254.169.254/latest
dynamic
meta-data
user-data

$ curl http://169.254.169.254/latest/user-data
(prints my specified user-data)

没有用户数据的实例

$ curl http://169.254.169.254/latest
dynamic
meta-data
(notice the absence of user-data)

$ curl http://169.254.169.254/latest/user-data
.... <title>404 - Not Found</title> ....

这回答了OP的问题,但不是John Bresnahan的经历

答案 2 :(得分:0)

对于所有URI,您必须在末尾使用“ /”。

curl http://169.254.169.254/latest/meta-data/
curl http://169.254.169.254/latest/user-data/

或者,您可以使用DNS记录“实例数据”代替IP。例如:

curl http://instance-data/latest/user-data/

答案 3 :(得分:-3)

从您的实例中获取用户数据脚本内容的最简单方法是执行以下操作:

curl http://169.254.169.254/latest/user-data | gunzip