Skip to content

Commit 557deef

Browse files
authored
fix: SQS filter S3 Object key in body TDE-1876 (#1181)
### Motivation Currently, the SQS subscription from the S3 bucket events uses `filterPolicy`, which only filters based on message attributes. However, S3 event notifications do **not include the object key as a message attribute** — the key is only present in the JSON message body. As a result, all messages are being filtered out (see `NumberOfNotificationsFilteredOut-NoMessageAttributes` metrics), preventing the SQS queue from receiving any messages. To solve this, we need to filter messages based on the object key inside the message body rather than expecting message attributes. <!-- TODO: Say why you made your changes. --> ### Modifications - use `filterPolicyWithMessageBody` instead of `filterPolicy`. <!-- TODO: Say what changes you made. --> <!-- TODO: Attach screenshots if you changed the UI. --> ### Verification <img width="1400" height="319" alt="image" src="https://github.com/user-attachments/assets/47491e2a-21d5-4da7-a066-fdf91a876af4" /> <!-- TODO: Say how you tested your changes. -->
1 parent 0e8df7c commit 557deef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

infra/eks/sqs/bucket.events.queue.construct.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Duration } from 'aws-cdk-lib';
2-
import { SubscriptionFilter, Topic } from 'aws-cdk-lib/aws-sns';
2+
import { FilterOrPolicy, SubscriptionFilter, Topic } from 'aws-cdk-lib/aws-sns';
33
import { SqsSubscription } from 'aws-cdk-lib/aws-sns-subscriptions';
44
import { Queue } from 'aws-cdk-lib/aws-sqs';
55
import { Construct } from 'constructs';
@@ -33,7 +33,15 @@ export class BucketEventsQueue extends Construct {
3333

3434
topic.addSubscription(
3535
new SqsSubscription(this.queue, {
36-
filterPolicy: { key: source.filter },
36+
filterPolicyWithMessageBody: {
37+
Records: FilterOrPolicy.policy({
38+
s3: FilterOrPolicy.policy({
39+
object: FilterOrPolicy.policy({
40+
key: FilterOrPolicy.filter(source.filter),
41+
}),
42+
}),
43+
}),
44+
},
3745
}),
3846
);
3947
}

0 commit comments

Comments
 (0)