An application running on an EC2 instance needs to determine the instance's public IPv4 address. What method should the application use to obtain it?
Choose an answer
Tap an option to check your answer.
Correct answer: Query the instance metadata endpoint at http://169.254.169.254/latest/meta-data/..
Why this is the answer
The correct method is to query the instance metadata endpoint at http://169.254.169.254/latest/meta-data/. This special IP address is a link-local address accessible only from the EC2 instance itself and provides various details about the instance, including its public IPv4 address, instance ID, and security credentials. Specifically, the public IPv4 address can be found at http://169.254.169.254/latest/meta-data/public-ipv4. Querying instance user data (http://169.254.169.254/latest/user-data/) would retrieve the script or data provided when the instance was launched, not its current public IP. Querying AMI information (http://169.254.169.254/latest/meta-data/ami/) would only provide details about the Amazon Machine Image used, not the instance's public IP. Reading the operating system hosts file would not contain the dynamic public IPv4 address assigned by AWS.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed