aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.39k stars 3.79k forks source link

s3, s3-notifications: allow configuring "Event Name" for Bucket event notifications #19869

Open ryparker opened 2 years ago

ryparker commented 2 years ago

Describe the feature

When I setup event notification for my S3 bucket. I'd like to specify the "Event Name" for the Event notification.

For example, I use the following code which setups up a Bucket that sends object created events to an SNS topic:

import { App, CfnOutput, RemovalPolicy, Stack } from 'aws-cdk-lib';
import { Bucket, EventType } from 'aws-cdk-lib/aws-s3';
import { SnsDestination } from 'aws-cdk-lib/aws-s3-notifications';
import { Topic } from 'aws-cdk-lib/aws-sns';

const app = new App();
const stack = new Stack(app, "sns-add-object-created-notification");

const topic = new Topic(stack, "Topic", {
  topicName: "my-topic",
  displayName: "My Topic",
});

const bucket = new Bucket(stack, "Bucket", {
  autoDeleteObjects: true,
  removalPolicy: RemovalPolicy.DESTROY,
});

bucket.addEventNotification(
  EventType.OBJECT_CREATED,
  new SnsDestination(topic)
);

new CfnOutput(stack, "TopicName", {
  value: topic.topicName,
});
new CfnOutput(stack, "BucketName", {
  value: bucket.bucketName,
});

This is what I see in the console > Bucket properties:

Screen Shot 2022-03-17 at 08 43 04

Notice the randomly generated name. Also notice that if I were to set this up manually using the AWS console then I have the ability to specify the event name:

Screen Shot 2022-03-17 at 08 44 49

Use Case

So that I can easily identify event notifications on S3 buckets.

Proposed Solution

The event name is not a supported CloudFormation configuration yet (feature-request here). However the way CDK currently sets up Bucket notifications is by deploying a lambda-backed custom resource. In this resource we might be able to pass a user defined name as the "Id" param for a Topic in the PutBucketNotificationConfiguration request.

Other Information

Opened on behalf of customer. SIM P60886631

Acknowledgements

CDK version used

2.15.0 (build 151055e)

Environment details (OS name and version, etc.)

Mac OS Monterey

osecen commented 1 year ago

When will this feature be implemented? A much needed one.

bartonjd commented 3 months ago

I would also like to see this added.