def create_account()

in source/Lambda/innovation_create_account_ou.py [0:0]


def create_account(client, name, email):
    try:
        logger.info("Creating Account: "+name)
        _account = client.create_account(
            Email=email,
            AccountName=name,
            IamUserAccessToBilling='DENY',
            RoleName="SandboxAdminExecutionRole"
        )

    except Exception as e:
        message = {'MESSAGE': 'Exception occurred while creating account','FILE': __file__.split('/')[-1], 
                              'METHOD': inspect.stack()[0][3], 'EXCEPTION': str(e), 'TRACE': traceback.format_exc()}
        logger.exception(message)
        raise

    _car = _account["CreateAccountStatus"]["Id"]

    account_check_retries = 0

    while account_check_retries < MAX_ACCOUNT_CHECK_RETRIES:
        account_check_retries = account_check_retries + 1
        account_status_response = client.describe_create_account_status(
            CreateAccountRequestId=_car)
        logger.info(account_status_response)
        account_status = account_status_response["CreateAccountStatus"]["State"]
        if account_status == "SUCCEEDED":
            return account_status_response["CreateAccountStatus"]["AccountId"]
        elif account_status == "FAILED":
            logger.error("ERROR: Account creation failed. Failure reason: "
                          + account_status_response["CreateAccountStatus"]["FailureReason"])
            raise Exception(account_status_response["CreateAccountStatus"]["FailureReason"])
        else:
            time.sleep(15)

    
    logger.error("Account creation taking longer than expected")
    raise Exception("Account creation taking longer than expected")