I can't seem to get my lambda to trigger as I would expect. In AWS EventBridge, I created a rule with the following custom event pattern:
{
"source": ["aws.s3"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["s3.amazonaws.com"],
"eventName": [
"CopyObject",
"CompleteMultipartUpload",
"PutObject"
],
"requestParameters": {
"bucketName": ["my-bucket"],
"key": [{"prefix": "folder1/folder2/"}]
}
}
}
but when I upload a file to the "directory" the rule does not trigger the lambda.
Can someone tell me where I've gone wrong?
You can use event notification in S3. It has direct integration with Lambda, SNS, SQS
Goto properties tab in S3
Navigate to Event notification. click on create event notification.

Then add the event name.
If you want to restrict the event to a specific folder or file type, you can fill in prefix or suffix fields or if you want it for entire bucket leave those blank.

Then select a list of events. like put, post.
Then choose the destination and click on save. You will be notified.

As of 2021-11-29, Amazon Event Bridge now supports Amazon S3 Event Notifications without having to enable CloudTrial.
In the properties of the S3 bucket you want to monitor, you have to enable Amazon EventBridge.

This will allow you to send messages to EventBridge using Rules.

In your eventbridge rule, you can configure lambda as a "Target". I made a step-by-step tutorial on how to configure eventbridge in AWS if you want to follow along: https://youtu.be/k-jEuNb_KBM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With