How to Get your Account Id with AWS CLI

avatar

Borislav Hadzhiev

Fri Sep 24 20211 min read

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).

To only return the account id, we've set the --query parameter to filter by the Account property.

In the command above, we've 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

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee