I need to check whether my EC2 instances are running properly.
I have written a script that will help me obtain the instance's ID and then send a notification to an SNS topic.
How can I obtain the instance's ID?
Click on the arrows to vote for the correct answer
A. B. C. D.Correct Answer: A.
Option A is CORRECT.
An instance's Meta data provides me with information about the instance like Instance ID, Local IP, Instance Type etc..I can query the instances Meta data using an internal IP http://169.254.169.254/latest/meta-data/ which can be accessed only from within an EC2 instance.
Option B is incorrect.
User Data is a section used for providing startup configuration to an EC2 instance.
Eg if I need to have an Apache web server running on an EC2 instance after it is provisioned, I can use the User Data section & provide scripts for installing the software during instance creation.
Option C is incorrect.
Meta data information is available to EC2 instances by default without the need to provide an IAM role for accessing it.
Option D is incorrect.
Console login or manual intervention is not required to achieve this task.
I can write a script & configure it to run at a scheduled time of the day wherein the EC2 instance can express itself to provide its health status.
References:
https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/instancedata-data-retrieval.html https://youtu.be/tPQsI8n6er0To obtain an instance's ID, you can use the instance's metadata service. This service provides a unique URL that you can use to access the instance's metadata, including its ID.
You can access the metadata service by making an HTTP GET request to the following URL: http://169.254.169.254/latest/meta-data/instance-id
This URL will return the instance's ID as plain text. You can then use this value in your script to send notifications to an SNS topic or perform other actions.
Note that you don't need to be authorized with an IAM role to access an instance's metadata. The metadata service is available to all instances, regardless of their IAM permissions.
In summary, the correct answer to this question is A: By querying the instance's Meta Data.