How polling works for long-running operations
mainIf an operation exceeds the 15-minute Lambda timeout, you can use polling. By defining @helper.poll_create, @helper.poll_update, or @helper.poll_delete decorators, crhelper will not send an immediate response to CloudFormation. Instead, it creates a CloudWatch Events schedule to re-invoke the Lambda every 2 minutes.
Polling Logic:
- The matching
@helper.poll_*function is called during re-invocation. - If the function returns
None, the schedule runs again in 2 minutes. - Once complete, return a
PhysicalResourceIDorTrue(to generate one). The schedule is then deleted and the response is sent to CloudFormation.
Required IAM Permissions: To use polling, the Lambda's IAM role must have the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:AddPermission",
"lambda:RemovePermission",
"events:PutRule",
"events:DeleteRule",
"events:PutTargets",
"events:RemoveTargets"
],
"Resource": "*"
}
]
}@helper.create
def create(event, context):
# This function will now trigger the polling mechanism
pass
@helper.poll_create
def poll_create(event, context):
# Logic to check if creation is complete
# Return True or a PhysicalResourceId when done
return True