Get AWS Account ID using CLI

Get AWS Account ID using CLI
Photo by Brett Jordan / Unsplash

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

💡
Used the --query parameter to filter by the Account property to only return the account id
aws sts get-caller-identity --query "Account" --output text

We also set the --output parameter to text to remove the double quotes around the account number.