This article contains the following sections:
- Fetching the AWS EC2 Instance ID from inside the Instance
- Fetching the AWS EC2 Instance ID from the EC2 Management Console
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:
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:
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.