Listing AWS Accounts in an AWS Organization

using aws-cli with a human-oriented output format

If you keep creating AWS accounts for every project, as I do, then you will build up a large inventory of accounts. Occasionally, you might want to get a list of all of the accounts for easy review.

The following simple aws-cli command pipeline:

  • filters to just the active (non-deleted) AWS accounts
  • sorts by account create/join time

and outputs the following values in nicely aligned columns:

  • AWS account id
  • account email address
  • account name

Here’s the command pipeline (contains some bash-ism):

aws organizations list-accounts \
  --output text \
  --query 'Accounts[?Status==`ACTIVE`][Status,JoinedTimestamp,Id,Email,Name]' |
  sort |
  cut -f2- |
  column -t -n -e -s$'\cI'

Here is a sample of what the output might look like:

317126648177          Organization (signin)
096053157110     Organization (development)
309325603118              Organization (qa)
516635816478      Organization (production)
161369730993       Organization (project-1)
631228168624       Organization (project-2)
132185502569       Organization (temporary)
852417106807  Organization (fooling-around)
758815767242      Organization (cloudtrail)
979811858263         Organization (backups)
402216494176             Completely Different Thing
258311671274         Organization (preview)
107177144177            Organization (beta)
402216494176           Organization (alexa)

Here’s an article where I describe how I use AWS Organizations to create and set up new AWS accounts with the aws-cli:

Creating AWS Accounts From The Command Line With AWS Organizations

[Update 20178-02-06: Switch from grep to JMESPath filter operator, thanks to reminder from Mike Fiedler]