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 org+signin@example.com Organization (signin) 096053157110 org+development@example.com Organization (development) 309325603118 org+qa@example.com Organization (qa) 516635816478 org+production@example.com Organization (production) 161369730993 org+project-1@example.com Organization (project-1) 631228168624 org+project-2@example.com Organization (project-2) 132185502569 org+temporary@example.com Organization (temporary) 852417106807 org+fooling-around@example.com Organization (fooling-around) 758815767242 org+cloudtrail@example.com Organization (cloudtrail) 979811858263 org+backups@example.com Organization (backups) 402216494176 another@example.com Completely Different Thing 258311671274 org+preview@example.com Organization (preview) 107177144177 org+beta@example.com Organization (beta) 402216494176 org+alexa@example.com 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]