cdk-custom-resource: Error for Lambda is initializing your function
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the bug
I have a Custom Resource in cdk code that calls a Lambda function.
Works fine most of the time. However, if we don't deploy this stack for a longer time we are seeing the following error message during deployment:
"failed to deploy: UPDATE_ROLLBACK_COMPLETE: Received response status [FAILED] from custom resource. Message returned: ERROR: Lambda is initializing your function. It will be ready to invoke shortly."
Seems to me that the lambda is in cold-start mode and a simple internal retry of calling the Lambda would fix the issue. If I rerun the deployment again, it will work.
I also found a Github Action that looks very similar to my error: https://github.com/aws/aws-cdk/issues/20123
But the fix attached to it does not apply to already existing Lambda functions.
I had already a support case open in AWS Support Center and their final advise was to open an issue here.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Library Version
_No response_
### Expected Behavior
The cdk should retry to call the Lambda function until it's ready if this error message comes back.
### Current Behavior
Error message:
"failed to deploy: UPDATE_ROLLBACK_COMPLETE: Received response status [FAILED] from custom resource. Message returned: ERROR: Lambda is initializing your function. It will be ready to invoke shortly."
### Reproduction Steps
```
const lambdaTrigger = new AwsCustomResource(construct, 'TriggerExistingLambdaCustomResource', {
timeout: Duration.minutes(5),
policy: AwsCustomResourcePolicy.fromStatements([
new PolicyStatement({
actions: ['lambda:InvokeFunction'],
effect: Effect.ALLOW,
resources: [dbMigrationLambda.functionArn],
}),
]),
onCreate: {
service: 'Lambda',
action: 'invoke',
parameters: {
FunctionName: dbMigrationLambda.functionName,
Payload: JSON.stringify({
'S3Bucket': bucketName,
'DatabaseName': databaseName
}),
},
physicalResourceId: PhysicalResourceId.of('invokeLambdaCreate-call-lambda'),
},
onUpdate: {
service: 'Lambda',
action: 'invoke',
parameters: {
FunctionName: dbMigrationLambda.functionName,
Payload: JSON.stringify({
'S3Bucket': bucketName,
'DatabaseName': databaseName
}),
},
physicalResourceId: PhysicalResourceId.of('invokeLambdaUpdate-call-lambda'),
},
installLatestAwsSdk: false,
});
```
### Possible Solution
Internal retry until the Lambda function is ready if this error message comes back.
### Additional Information/Context
_No response_
### AWS CDK Library version (aws-cdk-lib)
2.214.0
### AWS CDK CLI version
2.1025.0
### Node.js Version
20.19.5
### OS
Ubuntu 24.04.3
### Language
TypeScript
### Language Version
TypeScript 5.8.3
### Other information
_No response_
Contributor guide
Research direction
Start at the AwsCustomResource entry point and trace how its onCreate and onUpdate Lambda invoke operations handle the reported initialization error. Reproduce the TypeScript configuration from the issue, then verify that invocation retries occur for this specific message until the function is ready without breaking other failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100