Mikhail Novikov
Mikhail Novikov

Reputation: 633

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?

Upvotes: 8

Views: 16112

Answers (6)

Mukesh Soni
Mukesh Soni

Reputation: 129

I faced the same issue, The problem was with the function name itself. Try to check the value of the prefix to see if that matches perfectly with the resource.

If the resource is: resource/ and prefix is /test

then the actual folder path becomes: resource//test

just remove the '/' before test and it should work fine.

Upvotes: 1

Jacob Joy
Jacob Joy

Reputation: 556

Currently Under S3 there is option to Send notifications to Amazon EventBridge for all events in this bucket. Turn on

Upvotes: -1

SKN
SKN

Reputation: 11

Faced similar issues and figured our that the folder names should not have spaces.

Upvotes: 0

Omisha gupta
Omisha gupta

Reputation: 141

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.

Upvotes: 3

Yasser
Yasser

Reputation: 1369

Check the prefix in bucket/properties. If there is a world like foo/, that means that only the objects inside the foo folder will trigger the evert to lambda.

Upvotes: 1

notionquest
notionquest

Reputation: 39156

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

Upvotes: 3

Related Questions