- Newest
- Most votes
- Most comments
Your stack will eventually fail after hanging for approximately 1 hour. The default timeout for custom resources in CloudFormation is 3600 seconds (1 hour). Since your Lambda function isn't being invoked at all (as evidenced by the empty CloudWatch logs), CloudFormation is waiting for a response that will never come, and it will ultimately fail the stack operation when this timeout expires.
The most likely cause of your Lambda function not being invoked is a syntax error in your code. Looking at your import statement, you have import cfnresponse boto3 which is missing a comma or newline between cfnresponse and boto3. This syntax error would prevent the Lambda function from being created or deployed properly, which explains why there are no invocation logs.
To resolve this issue:
- Fix the import statement - It should be either:
import cfnresponse import boto3 import json
or
import cfnresponse, boto3, json
-
Consider setting a ServiceTimeout property on your custom resource to fail faster during development. Since you expect your Lambda to respond within 5 minutes (given your 300-second Lambda timeout), you could set
ServiceTimeout: 300in your custom resource definition. This way, if there's an error, CloudFormation will fail the stack operation after 5 minutes instead of waiting the full hour. However, make sure not to set this value too low - ensure your custom resource has enough time to perform its actions and return a response. -
Ensure your Lambda function sends a response to the pre-signed URL provided in the event, using the cfnresponse library or by manually sending a SUCCESS or FAILED status to the ResponseURL. Without this response, CloudFormation will always wait until timeout.
Once you fix the syntax error and redeploy, your Lambda function should be invoked properly and you'll see logs in CloudWatch.
Sources
Create custom provisioning logic with custom resources - AWS CloudFormation
CloudFormation custom resource request and response reference - AWS CloudFormation
Using AWS Lambda with CloudFormation - AWS Lambda
Relevant content
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated a year ago
