Quick way to get AWS Account number from the AWS CLI tools?

ehime picture ehime · Nov 18, 2015 · Viewed 41k times · Source

Looking for a quick way to pull my account number, I had originally thought of using aws iam get-account-authorization-details --max-items 1 but there are several issues with doing it this way. Is there a way to do this that might not cross account origins?

Answer

Taras Alenin picture Taras Alenin · Oct 19, 2016

You can get the account number from the Secure Token Service subcommand get-caller-identity using the following:

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