I ran this command to get the instance-id from a EC2 instance, how is the request processed and how does the service know what details to send back ?
wget -q -O - http://169.254.169.254/latest/meta-data/instance-id
thanks
To view instance metadata, you can only use the link-local address of 169.254. 169.254 to access. Requests to the metadata via the URI are free, so there are no additional charges from AWS. Using the curl tool on Linux or the PowerShell cmdlet Invoke-WebRequest on Windows, you will first create your token.
Instance metadata is data about your instance that you can use to configure or manage the running instance. Instance metadata is divided into categories, for example, host name, events, and security groups. You can also use instance metadata to access user data that you specified when launching your instance.
If you want to determine it from the EC2 instance, you can just try sending a request to http://169.254.169.254/ and see what the status code is.
The main difference between Data and Metadata is that data is simply the content that can provide a description, measurement, or even a report on anything relative to an enterprise's data assets. On the other hand, metadata describes the relevant information on said data, giving them more context for data users.
At a high level, wget
is a command that initiates an HTTP web request (pretending to be a browser) and those options tell it to spit out the resulting response to stdout (what you see).
Since the EC2 dom0 host controls the network stack as seen by your instance running in a virtual machine, EC2 can handle network traffic to 169.254.169.254 any way it wants.
In this case, EC2 knows what instance is making the request (whether it's based on your internal IP address controlled by EC2, or based on the fact that the dom0 host may be processing the request before it even gets sent across the network).
So, EC2 knows what instance is making the request and EC2 knows all the information about every instance, so EC2 can return the meta-data that is requested including the instance id.
Amazon hasn't published exactly how they have implemented this feature, but they do guarantee that it will return the correct data for the requesting instance with no chance of anybody else interfering.
You can learn more about available EC2 metadata here:
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?AESDG-chapter-instancedata.html
The magic IP address 169.254.169.254 and the corresponding meta-data URLs will not work outside of an EC2 instance, unless you happen to be running on a system which is trying to emulate EC2.
You can use ec2metadata
ec2metadata --instance-id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With