IMDSv2 meta-data query on EC2 returns 200 status but no data.

0

Hi,

When I run:

TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-id

I get response:

*   Trying 169.254.169.254:80...
* Connected to 169.254.169.254 (169.254.169.254) port 80 (#0)
> GET /latest/meta-data/instance-id HTTP/1.1
> Host: 169.254.169.254
> User-Agent: curl/8.0.1
> Accept: */*
> X-aws-ec2-metadata-token: ASDFSDF23424==
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Accept-Ranges: bytes
< Content-Length: 19
< Content-Type: text/plain
< Date: Sat, 17 Jun 2023 10:16:15 GMT
< Last-Modified: Sat, 17 Jun 2023 10:04:23 GMT
< X-Aws-Ec2-Metadata-Token-Ttl-Seconds: 21588
< Connection: close
< Server: EC2ws

I am connected to my instance with SSH. My instance security group allows SSH and ICMP only. I enabled metadata and V2 only.

Does anyone know why I'm getting this response and no attribute value?

Thanks,

neohed
gefragt vor einem Jahr453 Aufrufe
3 Antworten
2
Akzeptierte Antwort

Hi Neohed, Try running below command, i see there is a good possibility you might miss the instance-id as it gets printed immediately before shell prompt.

curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id && echo ""

Enter image description here

AWS
beantwortet vor einem Jahr
profile picture
EXPERTE
überprüft vor 2 Monaten
  • You're spot on mate. Thanks so much - that's brilliant! It worked perfectly.

0

Hi, The GET Api call represented in 3rd line of response is "> GET /latest/meta-data/instance-id HTTP/1.1" and i suspect that the URI is incorrect. Maybe you did a typo with your actual execution. If you had executed "curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/" as the command the API call should be made as "> GET /latest/meta-data/ HTTP/1.1".

AWS
beantwortet vor einem Jahr
  • Yes, you are correct, well spotted. I did indeed include the wrong command. When I run curl for "/latest/meta-data/" it works and I get a list of all available meta data. When I append a meta-data attribute name to the URL and try again, e.g., in my screenshot below, then I get this response.

0

@Abhishek Thanks for replying. I have tried these commands again and taken a screenshot:

AWS error

neohed
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen