aws / aws/aws-cdk

CustomResourceConfig: Logging retention not set for CR when "autoDeleteObjects: true" is added to S3 Bucket

Open
#33,116 4 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-s3 bug feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When "autoDeleteObjects: true" is added to an S3 bucket, CDK creates a Custom Resource to delete objects from the S3 Bucket. However, retention policy is not set on the created CloudWatch log group even with the CustomResourceConfig module is used. I suspect there may be other construct types that this configuration does not currently work for either.

Here's a sample of the code

```
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as logs from 'aws-cdk-lib/aws-logs';
import { App } from 'aws-cdk-lib';
import { CustomResourceConfig } from 'aws-cdk-lib/custom-resources';

export class CdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

CustomResourceConfig.of(this).addLogRetentionLifetime(logs.RetentionDays.TWO_WEEKS);

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

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Version

_No response_

### Expected Behavior

The CloudWatch log group created by the custom resource should have retention policy set.

### Current Behavior

CloudWatch log group created by the custom resource does not have retention policy set.

### Reproduction Steps

- Create an S3 bucket with "autoDeleteObjects: true" property set
- Add CustomResourceConfig module to set log retention policy on log group

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.176.0

### Framework Version

_No response_

### Node.js Version

v20.17.0

### OS

MacOS

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with CustomResourceConfig and the S3 Bucket autoDeleteObjects path, using the supplied TypeScript reproduction to trace how the custom resource and its CloudWatch log group are created. Confirm the configured retention is applied to that log group and check whether the same gap affects other custom-resource constructs mentioned in the report.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.