| by Arround The Web | No comments

How to Fetch the AWS EC2 Instance ID

Every EC2 instance has its unique ID, which can be used to locate the instance from a list. The name of the instance can be used repeatedly, and it can create doubt about your instance. Locating your instance from a bunch of other instances can get tricky sometimes. It is very easy to fetch your instance ID from the metadata of the EC2 instance. There are two different methods of fetching the instance ID and both these methods will be covered in this article.

This article contains the following sections:

Let’s start with how to fetch the AWS EC2 instance ID from inside the instance.

Fetching the AWS EC2 Instance ID From Inside the Instance

To fetch the AWS EC2 instance ID, you must first connect to the EC2 instance. For that, you simply need to copy the command from the “Connect” page and paste it on the command prompt. Then change the path of the key pair file from your PC then simply press enter, and you will be connected to the EC2 instance:

The AWS EC2 instance ID will be stored in the metadata, and to fetch the instance ID, you need to check into the metadata. For that, simply type the following command:

curl http://169.254.169.254/latest/meta-data

This command will show you the list of all the metadata from where you can locate the EC2 instance ID:

To fetch the EC2 instance ID simply type the following command:

curl http://169.254.169.254/latest/meta-data/instance-id

This command will fetch you the EC2 instance ID.

You have successfully fetched the EC2 instance ID from inside the instance and now let’s talk about how to fetch the AWS EC2 instance ID from the EC2 management console.

Fetching the AWS EC2 Instance ID From the EC2 Management Console

To fetch the instance ID using the EC2 console, you need to click on the “Instances” tab from the left panel and you will get the instance ID in the list of the instances:

You can also get your instance ID by clicking on the instance and scroll down in the “Details” section. You can copy the instance ID from this section:

You have successfully fetched the EC2 instance ID from the AWS EC2 management console.

Conclusion

To fetch the EC2 instance ID you need to connect to SSH of your EC2 instance by copying the command from the “Connect” page. After connecting to the EC2 instance you need to type in a command to get the EC2 instance ID and press enter then it will show you the EC2 instance ID. The instance ID can be fetched from the EC2 management console by clicking on the instance and visiting its details mentioned under the Ec2 instance.

Share Button

Source: linuxhint.com

Leave a Reply