User Tools

Site Tools


aws:list_accounts_in_org

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
aws:list_accounts_in_org [23/06/2025 16:14] andrewaws:list_accounts_in_org [01/07/2025 13:37] (current) andrew
Line 1: Line 1:
 list_accounts_in_organisations.sh list_accounts_in_organisations.sh
- 
 <code bash> <code bash>
 #!/bin/bash #!/bin/bash
Line 14: Line 13:
 # Using jq to parse the JSON # Using jq to parse the JSON
 aws organizations list-accounts | jq -r '.Accounts.[].Id' aws organizations list-accounts | jq -r '.Accounts.[].Id'
 +
 +</code>
 +
 +
 +Iterates over the accounts in an organisation.
 +<code>
 +#!/bin/bash
 +
 +ACCOUNTS_RAW=$(aws organizations list-accounts --query 'Accounts[*].[Id]' --output json | jq -c .[][] | tr -d '\n')
 +ACCOUNTS="${ACCOUNTS_RAW//\"/ }"
 +
 +echo "accounts_raw:- ${ACCOUNTS_RAW}"
 +echo "accounts is:- $ACCOUNTS"
 +
 +for ACCOUNT in $ACCOUNTS
 +do 
 +    echo "Account is >${ACCOUNT}<"
 +    echo "do some work on each account"
 +done
  
 </code> </code>
  
aws/list_accounts_in_org.1750695286.txt.gz · Last modified: by andrew

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki