aws-cloudformation / aws-cloudformation/custom-resource-helper

Poller persistence

Open
#27 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
382
Forks
61
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Research direction

Start by tracing helper.Data.update and helper.Data.get across the helper.poll_create lifecycle, then inspect how the poll state is serialized between invocations. Reproduce the AWS Organizations CreateAccount flow and verify that CreateAccountRequestId is available on the next invocation and that the stored AccountId and AccessRole remain available after success.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.