Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda function trigger on object creation in S3 does not work

I am doing an upload like this:

curl -v -X PUT -T "test.xml" -H "Host: my-bucket-upload.s3-eu-central-1.amazonaws.com" -H "Content-Type: application/xml" https://my-bucket-upload.s3-eu-central-1.amazonaws.com/test.xml

The file gets uploaded and I can see it in my S3 bucket.

The trick is, when I try to create a lambda function to be triggered on creation, it never gets invoked. If I upload the file using the S3 web interface, it works fine. What am I doing wrong? Is there any clear recipe on how to do it?

like image 465
Mikhail Novikov Avatar asked Jun 27 '26 06:06

Mikhail Novikov


2 Answers

Amazon S3 APIs such as PUT, POST, and COPY can create an object. Using these event types, you can enable notification when an object is created using a specific API, or you can use the s3:ObjectCreated:* event type to request notification regardless of the API that was used to create an object.

  • Check the notification event setup on the bucket
  • Go to bucket on AWS management console
  • Click the properties tab on the bucket
  • Click the Events to check the notification event setup

Case 1:

  • s3:ObjectCreated:* - Lambda should be invoked regardless of PUT, POST or COPY

Other case:-

  • If the event is setup for specific HTTP method, use that method on your CURL command to create the object on S3 bucket. This way it should trigger the Lambda function
like image 64
notionquest Avatar answered Jun 29 '26 14:06

notionquest


Make sure the prefix you're adding contains safe special characters mentioned here. As per AWS documentation, some characters require special handling. Please be mindful of that.

Also, I noticed modifying the trigger on lambda page doesn't get applied until you delete the trigger and new one (even if it is same). Learned hard way. AWS does behaves weird sometime.

like image 23
Omisha gupta Avatar answered Jun 29 '26 16:06

Omisha gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!