Warm tip: This article is reproduced from serverfault.com, please click

Getting Multiple Items from AWS EC2 Metadata Link-Local Address

发布于 2020-11-29 17:30:38

I am trying to retrieve multiple items from the AWS EC2 link local address

It can be done using multiple calls to the link-local address:

[ec2-user ~]$ curl http://169.254.169.254/latest/meta-data/instance-id
i-1234567890abcdef0

[ec2-user ~]$ curl http://169.254.169.254/latest/meta-data/instance-type
p3.2xlarge

These kind of calls are throteled by AWS

Is there a way to make a single call to get both?

Questioner
orgoro
Viewed
0
Andre.IDK 2020-11-30 16:09:00

You can retrieve both info by making a request to the Instance identity document.

curl http://169.254.169.254/latest/dynamic/instance-identity/document

This will return a JSON that looks like this:

{
    "devpayProductCodes" : null,
    "marketplaceProductCodes" : [ "1abc2defghijklm3nopqrs4tu" ], 
    "availabilityZone" : "us-west-2b",
    "privateIp" : "10.158.112.84",
    "version" : "2017-09-30",
    "instanceId" : "i-1234567890abcdef0",
    "billingProducts" : null,
    "instanceType" : "t2.micro",
    "accountId" : "123456789012",
    "imageId" : "ami-5fb8c835",
    "pendingTime" : "2016-11-19T16:32:11Z",
    "architecture" : "x86_64",
    "kernelId" : null,
    "ramdiskId" : null,
    "region" : "us-west-2"
}