Skip to content

(aws-s3): retention on S3 autoDeleteObjects lambda CloudWatch log group is Never expire #24815

@ozeebee

Description

@ozeebee

Describe the bug

Currently, when setting autoDeleteObjects on a S3 bucket to true, the lambda creates a log group whose retention is set to 'Never expire'.
When deploying/destroying a lot of stacks (typically during development), this generates a lot of log groups (with pattern /aws/lambda/$StackName-CustomS3AutoDeleteObjects-$someid) that will stay there forever unless manually cleaned up.

Expected Behavior

We should be able to override the default log group retention or have a reasonable log retetion period for those logs (for instance 3 months).

Current Behavior

The log group is kept forever, retention is 'Never expire'.

Reproduction Steps

Create a bucket with autoDeleteObjects such as:

const bucket = new s3.Bucket(this, 'MyTempFileBucket', {
  removalPolicy: cdk.RemovalPolicy.DESTROY,
  autoDeleteObjects: true,
});

Then deploy/destroy the stack mulitple times, this will generate a different log group for each cycle, and all of them will be on CW logs forever unitl manually deleted.

Possible Solution

Either expose a log retention period for the lambda, for instance:

const bucket = new s3.Bucket(this, 'MyTempFileBucket', {
  removalPolicy: cdk.RemovalPolicy.DESTROY,
  autoDeleteObjects: true,
  autoDeleteObjectsLambdaLogRetention: logs.RetentionDays.THREE_MONTHS
});

or set a default log retention period other than 'Never expire' (3 months seems reasonnable).

Additional Information/Context

No response

CDK CLI Version

2.69.0 (build 60a5b2a)

Framework Version

No response

Node.js Version

v18.12.0

OS

macOS 12.6

Language

Typescript

Language Version

4.9.5

Other information

No response

Metadata

Metadata

Labels

@aws-cdk/aws-s3Related to Amazon S3effort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions