To get your account id using AWS CLI, run the
command, setting the
--query parameter to
Account to filter the output.
aws sts get-caller-identity --query "Account" --output text
The get-caller-identity command returns the User Id, Account Id, and the ARN of the caller (User or role).
--queryparameter to filter by the
Accountproperty 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
You can also redirect the output from the command to a file on the local file system:
aws sts get-caller-identity --query "Account" --output text > account-id.txt
To get your account Id using the AWS console, you have to click on your username in the navigation bar.
You can learn more about the related topics by checking out the following tutorials: