How to Get your Account ID with AWS CLI

avatar
Borislav Hadzhiev

Last updated: Feb 26, 2024
2 min

banner

# Get your Account ID using AWS CLI

To get your account ID using AWS CLI, run the sts get-caller-identity command, setting the --query parameter to Account to filter the output.

shell
aws sts get-caller-identity --query "Account" --output text

get account id aws cli

The get-caller-identity command returns the User ID, Account ID, and the ARN of the caller (User or role).

We used the --query parameter to filter by the Account property to only return the account ID.

We also set the --output parameter to text to remove the double quotes around the account number. By default, the output is set to JSON.

You can also redirect the output from the command to a file on the local file system.

shell
aws sts get-caller-identity --query "Account" --output text > account-id.txt

redirect account id to file

To get your account ID using the AWS console, you have to click on your username in the navigation bar.

get account id aws console

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.