0

The instance-id returned from a curl request to http://169.254.169.254/latest/meta-data/instance-id appears to be the EC2 instance ID that runs that particular curl request in this case, to terminate that particular instance.

Will this always be the case - i.e. is http://169.254.169.254/latest/meta-data/instance-id a reliable way of quickly/easily retrieving the instance-id, or is there more to it? (I'm slightly suspicious of the use of 'latest' in the url - and want to check that this curl request is doing exactly as I think it does - returning the instance-id of the EC2 from which the curl request originates, and not something different, like the 'latest' instance launched in that group etc)

stevec
  • 41,291
  • 27
  • 223
  • 311
  • You might want to read [this AWS document](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-categories) – Toris Jul 11 '19 at 18:56
  • 1
    The `latest` portion refers to potential changes to the format of the response. It is possible to request a particular version of the `meta-data` response, to provide backwards compatibility. Specifying `latest` will use the latest version of the `meta-data` response format. It should be perfectly fine for your use-case. – John Rotenstein Jul 12 '19 at 01:00

1 Answers1

3

From official EC2 document Instance Metadata and User Data

Instance metadata is data about your instance that you can use to configure or manage the running instance.

The IP address 169.254.169.254 is a link-local address and is valid only from the instance.

And from Examples of Retrieving Instance Metadata section

[ec2-user ~]$ curl http://169.254.169.254/
1.0
2007-01-19
2007-03-01
...
2016-06-30
2016-09-02
latest

I think it's the one you want, as far as I understand exactly exactly.

Community
  • 1
  • 1
Toris
  • 2,348
  • 13
  • 16