-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws-logs: race condition with AWS Lambda default log groups #32689
Comments
@garysassano , I think the
|
@khushail I'm a bit confused. Where do you see that I'm using the |
Something similar to this: aws/serverless-application-model#1216 (comment).
|
@Dreamescaper That's actually a smart solution. |
Apologies for the confusion here. By
However I agree in some cases, this might lead to race condition and recreating the log group when its not desired. |
Describe the bug
my-stack.ts
In this scenario, all client functions are triggered by the EventBridge Scheduler every minute. During stack destruction via
cdk destroy
, there is a possibility that one of the Lambda functions could be invoked simultaneously. This results in the recreation of the default log group at/aws/lambda/{function-name}
, even if it had just been deleted a few seconds earlier.Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
CDK should guarantee that AWS Lambda log groups are always deleted last to avoid race conditions.
Current Behavior
One of the Log Groups seemed to survive the stack destruction despite having
RemovalPolicy.DESTROY
set. However, upon closer inspection, you can notice the retention period is set toNever expire
, whereas in our stack we definedRetentionDays.ONE_WEEK
. And that's because while the CDK was destroying the log group defined in our stack, the Lambda function got invoked, thus creating a new log group not managed by the CDK and with the default retention policy, which isNever expire
.Reproduction Steps
see above.
Possible Solution
One possible workaround is to create the log groups first, and assign them to each Lambda function directly at creation time.
However, this approach introduces additional complexity and makes the code less clean.
A more convenient solution would be to introduce a
Function.addLogGroup()
method, enabling users to link a log group to a Lambda function as a dependency within the same AWS CDK stack but in a different section of the code.feature.ts
Additional Information/Context
No response
CDK CLI Version
2.173.4
Framework Version
No response
Node.js Version
22.12.0
OS
Ubuntu 24.04.1
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: