S3 event notification stack1 overwrite notification stack2

Hi everyone,

I had problems with class S3BucketNotification, I’m using in two stack, but when I execute on second stack, overwrite the s3 event notification created on first stack.

stack1 -> bucketS3Notification1
stack2 -> bucketS3Notification2

Example

stack1.ts

// Bucket Notification Config
const s3BucketNotificationConfig: S3BucketNotificationConfig = {
bucket: bucketName,
lambdaFunction: [
{
lambdaFunctionArn: lambdaFunc.arn,
id: “lambda-event-processing-01”,
events: [“s3:ObjectCreated:*”],
filterPrefix: “dirname/process_control/”,
filterSuffix: “.csv”,
},
],
};

// Create S3 Event Notification
new S3BucketNotification(
  this,
  "s3-bucket-notification-01",
  s3BucketNotificationConfig
);

stack2.ts

const s3BucketNotificationConfigCompat: S3BucketNotificationConfig = {
bucket: bucketName,
lambdaFunction: [
{
lambdaFunctionArn: lambdaFunc.arn,
id: “lambda-event-processing-02”,
events: [“s3:ObjectCreated:*”],
filterPrefix: “dirname/op_compat/”,
filterSuffix: “.txt”,
},
]
};

    // Create S3 Event Notification
    new S3BucketNotification(
        this,
        "s3-bucket-notification-02",
        s3BucketNotificationConfigCompat
    );

Hi @Noobcloud :wave:

I saw that you got this reply on CDK Dev Slack:

Matthew Bonig 3 days ago:
Yeah, I’ve seen this before in some other cases. Notifications are whole definitions, so you can’t have notifications defined in two different places. Take a look at using Event Bridge in this case

So, I guess this is resolved now?

Hello @ansgarm ,

No, I’m reading more aws doc to understand what mean “Take a look at using Event Bridge in this case”. I found this blog article New – Use Amazon S3 Event Notifications with Amazon EventBridge | AWS News Blog, then I thinks I need to figure out how to integrate this with Terraform CDKTF.

Thanks.