Created
March 1, 2021 05:14
-
-
Save jsamuel1/6af7b26ae1567cf845959fadc655e27a to your computer and use it in GitHub Desktop.
Revisions
-
jsamuel1 created this gist
Mar 1, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ #!/usr/bin/env python from __future__ import print_function import boto3 import botocore import time import sys import argparse def move_account_ou( organization_unit_id, new_org_id, account_id ): client = boto3.client('organizations') try: move_account_response = client.move_account(AccountId=account_id, SourceParentId=organization_unit_id, DestinationParentId=new_org_id) except botocore.exceptions.ClientError as e: print(e) sys.exit(1) def main(arguments): organization_unit_id = 'ou-xxxx-xxxxxxxx' new_org_id = 'r-xxxx' client = boto3.client('organizations') accounts = client.list_accounts_for_parent(ParentId=organization_unit_id, MaxResults=10) print(accounts) for account in accounts['Accounts']: print(account) move_account_ou(organization_unit_id, new_org_id, account['Id']) if __name__ == '__main__': sys.exit(main(sys.argv[1:]))