aws:organisations
Table of Contents
Organisations
Get Root ID
With text output:-
OrgRoot=$(aws organizations list-roots --query 'Roots[0].Id' --output text)
Using JQ:-
OrgToot=$(aws organizations list-roots | jq -r .Roots.[0].Id)
Get a list of OU's in an organisation
OU_IDs=$(aws organizations describe-organization --query 'Organization.Id' --output text)
#!/bin/bash # Get the root of an Org and find the subordinate OUs in it. ROOT_ID=$(aws organizations list-roots | jq -r .Roots.[0].Id) printf "Root ID:- ${ROOT_ID}\n" OUS=$(aws organizations list-organizational-units-for-parent --parent-id "${ROOT_ID}" | jq -c .OrganizationalUnits.[].Id) printf "OUs:- ${OUS}\n\n"
Seearch for an OU by name:-
SpecificOU=$(aws organizations list-organizational-units-for-parent \ --parent-id $RootId \ --query 'OrganizationalUnits[?Name==`SpecificOU`].Id' --output text )
List Accounts in OU / Org
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
Truncate account number
Sometimes you may want to point to an account, but not reveal the full account number, this code will truncate your account to a specified length.
$ cat truncate.py #!/usr/bin/python3 account = '123456784321' removechar = 6 result1 = account[removechar:] result2 = account[removechar:len(account)] print(result1, result2) $ ./truncate.py 784321 784321
aws/organisations.txt · Last modified: by andrew