Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get AWS Account ID using awscli

How can I get the AWS Account ID using awscli?

I look for something like

$ aws <service> <options>
123456789012

Close, but not what I'm looking for: $ aws iam get-user.

like image 219
Costin Avatar asked Jan 03 '18 18:01

Costin


People also ask

How do I get my AWS account ID from command line?

Finding Your Account ID using the AWS CLI Use the following command to view your user ID, account ID, and your user ARN: aws sts get-caller-identity.

Can you expose AWS account ID?

AWS account IDs are not considered sensitive and you need not worry about sharing them via screenshot, code snippet, ill-considered tweet, or any other medium that you'd like.

How can I see my AWS CLI profile?

In order to see which your default AWS CLI profile is, run the aws configure list command. The command shows the name of the default profile, the profile's security credentials and region. Copied! We can see that the default profile's name is tester in the example.

How do I find my AWS EC2 instance account number?

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.


2 Answers

The following command returns the account number:

aws sts get-caller-identity --query 'Account' --output text

Command details can be found here

(reformat the command as code session)

like image 136
krishna_mee2004 Avatar answered Oct 29 '22 15:10

krishna_mee2004


Need to get an AWS Account ID from the aws cli tool? Here you go:

aws sts get-caller-identity --output text --query 'Account'

like image 21
Saurabh Srivastava Avatar answered Oct 29 '22 15:10

Saurabh Srivastava