Thursday, October 27, 2022

[SOLVED] how to get aws account number /id based on EC2 instance which is hosted in amazons

Issue

how to get aws account number /id based on EC2 instance ip which is hosted in amazon i have a instance name CTI server it is hosted in one AWS account. I have the details of CTI server like private ip and hosts and able to do ssh this instance through putty .I want the AWS account number /aws account ID of where this instance is created . is their any command to find out account number without login into aws console


Solution

You can obtain the account number from within an EC2 instance by querying the instance metadata. The metadata is located in http://169.254.169.254/latest/dynamic/instance-identity/document.

If an IAM role is attached to the instance, you can retrieve it using:

aws sts get-caller-identity


Answered By - krishna_mee2004
Answer Checked By - Willingham (WPSolving Volunteer)