(aws-s3): introduce method to set or change server access logging configuration
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
Currently in CDK (v2.66.1 at time of writing) the S3 Bucket construct allows you to set the Server Access Logging configuration via constructor parameters, see [here](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html#serveraccesslogsbucket) and [here](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html#serveraccesslogsprefix). However there is no option for you to set or change this after the bucket has been initialised. It would be handy if this functionality was available via the construct [methods](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.Bucket.html#methods).
### Use Case
We wanted to have a single shared access log bucket from which all our other buckets would write their access logs to. Then, leveraging the `serverAccessLogsPrefix` functionality we'd ensure each bucket segregated their logs within this shared space by its own bucket name, for example:
```
/shared-access-log-bucket
- /bucket-foo
- /bucket-bar
- /etc...
```
However we're unable to do this as things stand, eg:
```typescript
const foo = new s3.Bucket(scope, id, {
serverAccessLogsBucket: sharedAccessLogBucket,
serverAccessLogsPrefix: ??? // <-- we don't know what 'foo.bucketName' is yet and this is our only chance to set this
})
```
### Proposed Solution
Being able to do something like the following is what I'm suggesting:
```typescript
const foo = new s3.Bucket(scope, id);
foo.addServerAccessLogging({
serverAccessLogsBucket: sharedAccessLogBucket,
serverAccessLogsPrefix: foo.bucketName // <-- this is now known at this point
})
```
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
v2.66.1
### Environment details (OS name and version, etc.)
n/a
Contributor guide
Research direction
Start with the aws_s3.Bucket construct, its serverAccessLogsBucket and serverAccessLogsPrefix constructor options, and its existing methods. Trace how those options become the S3 logging configuration, then assess the proposed post-construction method for the shared log bucket and bucketName prefix case. Done means logging can be configured after initialization with the requested bucket and prefix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100