简体   繁体   中英

Error 404 trying to get metadata from an AWS EC2 instance with PHP

I'm trying to get the user-data from an AWS EC2 instance with PHP using:

<?php
$instance_id = file_get_contents("http://instance-data/latest/meta-data/user-data");
?>

However, I keep getting:

PHP Warning:  file_get_contents(http://instance-data/latest/meta-data/user-data): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in ... while reading response header from upstream, client: ..., server: ..., request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"...

Why?

Ok, it was an easy error - that cost me a lot of time -.

The path should be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM