Created
January 24, 2018 03:19
-
-
Save reecestart/767d4e6fd23d020f1333e41d9678e6c5 to your computer and use it in GitHub Desktop.
Create AWS Account with Python using Organizations
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 characters
import time | |
import boto3 | |
import pprint | |
# setup pprint | |
pp = pprint.PrettyPrinter(indent=1) | |
# define the connection | |
client = boto3.client('organizations') | |
# If you're using Python 3 change the below raw_input to input | |
NewAccountEmail = raw_input('Enter a unique Email Address for the new AWS account: ') | |
NewAccountName = raw_input('Enter the Name for the new AWS account: ') | |
NewAccountRole = raw_input('Enter the Name for Administrative Role the new AWS account: ') | |
response = client.create_account( | |
Email=NewAccountEmail, | |
AccountName=NewAccountName, | |
RoleName=NewAccountRole, | |
IamUserAccessToBilling='ALLOW' | |
) | |
CreateAccountStatus = str(response['CreateAccountStatus']['Id']) | |
pp.pprint('Checking Create Account Request Id: ' + CreateAccountStatus) | |
time.sleep(10) # delays for 10 seconds because the organizations client doesn't have a waiter | |
response = client.describe_create_account_status( | |
CreateAccountRequestId=CreateAccountStatus | |
) | |
NewAccountID = str(response['CreateAccountStatus']['AccountId']) | |
pp.pprint('New Account Id: ' + NewAccountID) | |
pp.pprint('New Account Name: ' + NewAccountName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just an update, you can create custom
waiter