AWS – List all Accounts in Organization via CLI

July 1, 2021

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, -k2
Code language: Bash (bash)