Get your AWS Account ID using AWS CLI
If you have not already done so, install and configure AWS CLI.
Get your AWS Account ID
To get your AWS Account ID, run the following command:
aws sts get-caller-identity --query Account --output text
This command uses the Security Token Service (STS) get-caller-identity function, which returns details about the IAM user or role making the call. The --query Account fetches only the Account ID, and --output text ensures the result is displayed as plain text.
Understanding the output
The output of the get-caller-identity
command provides three pieces of information:
UserId
: The unique identifier for the entity making the call. For an IAM user, this is the user's unique ID.Account
: Your AWS Account ID.Arn
: The Amazon Resource Name (ARN) of the IAM user or role making the call.
By using the --query Account
parameter, we specifically extract the Account value.
Saving the output to file
You can save the output of the get-caller-identity
command to a file using the >
operator as shown below:
aws sts get-caller-identity --query Account --output text > account-id.txt
This will save the output to a file called account-id.txt
in the current directory.
Need Help? Open a discussion thread on GitHub.
Related Posts
📄
Mount Amazon FSX Lustre filesystem and attack to AWS EC2 instance
📄
Mount Amazon EFS Drive on EC2 Ubuntu Linux using NFS Utils
📄
How to install and configure AWS CLI on Linux with Autocompletion
📄
How to Install and Run WordPress on an EC2 Instance
📄
Migrate a DB to RDS using AWS Database Migration Service (DMS)