You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a Custom resource to create an account inside AWS Organization.
This action is asynchronous because you have to call two different boto3 method: first you need to call the CreateAccount API, this provide you a request id which needs to be used polling the DescribeCreateAccountStatus API until the create status is SUCCEEDED.
I would like to persist the RequestId putting it in the ChHelperData, but calling this is not enought helper.Data.update({"CreateAccountRequestId": create_account_request_id})
I don't find anything inside the event inside the ChHelperData during the next invocation.
Here the code I'm developing:
@helper.poll_create
def create_account(event, _):
organizations_client = boto3.client('organizations')
create_account_request_id = helper.Data.get("CreateAccountRequestId")
if not create_account_request_id:
account_name = event.get("ResourceProperties", {}).get('AccountName')
if not account_name:
raise ValueError("AccountName is not specified")
account_email = f"{account_name}@{INFO_DOMAIN}"
response = organizations_client.create_account(
Email=account_email,
AccountName=account_name,
)
create_account_request_id = response['CreateAccountStatus']['Id']
if not create_account_request_id:
print(response)
raise ValueError("CreateAccountRequestId not found")
helper.Data.update({"CreateAccountRequestId": create_account_request_id})
else:
response = organizations_client.describe_create_account_status(
CreateAccountRequestId=create_account_request_id,
)
status = response['CreateAccountStatus']['State']
print(f"Account creation status: {status}")
if status == 'FAILED':
raise RuntimeError(response['CreateAccountStatus']['FailureReason'])
if status == 'SUCCEEDED':
account_id = response['CreateAccountStatus']['AccountId']
helper.Data.update({
"AccountId": account_id,
"AccessRole": f"arn:aws:iam::{account_id}:role/OrganizationAccountAccessRole"
})
return account_id
The text was updated successfully, but these errors were encountered:
Hi,
I'm trying to create a Custom resource to create an account inside AWS Organization.
This action is asynchronous because you have to call two different boto3 method: first you need to call the
CreateAccount
API, this provide you a request id which needs to be used polling theDescribeCreateAccountStatus
API until the create status is SUCCEEDED.I would like to persist the RequestId putting it in the ChHelperData, but calling this is not enought
helper.Data.update({"CreateAccountRequestId": create_account_request_id})
I don't find anything inside the event inside the ChHelperData during the next invocation.
Here the code I'm developing:
The text was updated successfully, but these errors were encountered: