Skip to content

storage-class in event bridge rule

0

I set up a event bridge rule like: { "source": ["aws.s3"], "detail-type": ["Object Created"], "detail": { "bucket": { "name": ["dev-iamcsi-datalake-bronze"] }, "object": { "key": [{ "prefix": "data/log/" }], "storage-class": ["STANDARD"] } } }. But when there is object of Standard class create, the rule was not triggered. If I remove ""storage-class": ["STANDARD"]", there will be event matched. So, how can i properly set the rule so that only object with standard storage class created will trigger the rule? Thanks!

asked a month ago77 views

2 Answers
3
Accepted Answer

I think the reason your rule is not triggering is that the storage-class attribute is not included in the S3 Object Created event payload that is sent to EventBridge. Because the field simply does not exist in the incoming JSON, the rule fails to match.

I would try: Remove the "storage-class" filter from your EventBridge rule so it successfully triggers based on the bucket and prefix. Then, inside your target resource (e.g., an AWS Lambda function), perform an S3 HeadObject API call to retrieve the object's metadata. You can then check the storage class programmatically and execute your logic only if it equals STANDARD.

Why do I think so? You can review the JSON payload structure that S3 sends to EventBridge in the official AWS Documentation here: EventBridge event message structure - Amazon S3

As shown in the official examples, the detail.object node only provides the key, size, etag, version-id, and sequencer. It does not provide the storage class.... .

EXPERT

answered a month ago

EXPERT

reviewed a month ago

0

The issue you're experiencing is likely due to how the storage-class field is being matched in your event pattern. When working with EventBridge event patterns, it's important to ensure that the field names and values exactly match what appears in the actual events from the source.

Here are a few things to check and try:

  1. Verify the actual event structure: The storage-class field might not be present in the event exactly as you've specified, or it might be named differently. I recommend using the EventBridge console to examine actual events from your S3 bucket to see the exact field name and value format.

  2. Check the field name casing: Event patterns are case-sensitive. Ensure that "storage-class" matches exactly how it appears in the S3 events - it could be "storageClass", "StorageClass", or another variation.

  3. Validate your event pattern: You can test your event pattern using the EventBridge console or the AWS CLI's test-event-pattern command. This will help you verify whether your pattern matches sample events before deploying it.

  4. Make your pattern more precise: Following best practices, ensure you're specifying filters for both event metadata (source and detail-type, which you already have) and the specific event data fields you need. The more precise your pattern, the better it will match only the events you want.

If removing the storage-class filter allows events to match, this strongly suggests that either the field name doesn't match exactly, the value format is different, or the field might not be present in all Object Created events. I recommend capturing a sample event first to see its exact structure, then adjusting your event pattern accordingly.
Sources
Getting started: Create an Amazon EventBridge event bus rule - Amazon EventBridge
Best practices for Amazon EventBridge event patterns - Amazon EventBridge

answered a month ago

EXPERT

reviewed a month ago

  • How can i use EventBridge console to exam actual event? From the Sandbox under console, I see sampel event like "{ "version": "0", "id": "17793124-05d4-b198-2fde-7ededc63b103", "detail-type": "Object Created", "source": "aws.s3", "account": "123456789012", "time": "2021-11-12T00:00:00Z", "region": "ca-central-1", "resources": ["arn:aws:s3:::example-bucket"], "detail": { "version": "0", "bucket": { "name": "example-bucket" }, "object": { "key": "example-key", "size": 5, "etag": "b1946ac92492d2347c6235b4d2611184", "version-id": "IYV3p45BT0ac8hjHg1houSdS1a.Mro8e", "sequencer": "00617F08299329D189" }, "request-id": "N4N7GDK58NMKJ12R", "requester": "123456789012", "source-ip-address": "1.2.3.4", "reason": "PutObject" } }", which has no storage class. Can someone from AWS clarifiy that storage class is included in event or not? Thanks!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.