AWS – List all Accounts in Organization via CLI

I find myself constantly referencing the account number and name of AWS accounts across the organization. I came up with this script to print out the account number and name of each account:

#!/bin/bash
aws organizations list-accounts \
--output text \
--query 'Accounts[?Status==`ACTIVE`][Id,Name]' | \
awk '{ print $1","$2 }' | \
sort -t, -k2Code language: Bash (bash)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.