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)
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 )
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