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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
At a high level,
wgetis 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:
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.