8

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?

0xCursor
  • 2,242
  • 4
  • 15
  • 33
Mikhail Novikov
  • 623
  • 2
  • 9
  • 23
  • 1
    There are various events for adding new objects. can you show the lambda trigger configuration? – johni May 23 '17 at 13:55

5 Answers5

3

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
notionquest
  • 37,595
  • 6
  • 111
  • 105
2

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.

Omisha gupta
  • 121
  • 1
  • 6
1

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.

0xCursor
  • 2,242
  • 4
  • 15
  • 33
Yasser
  • 1,159
  • 1
  • 14
  • 19
0

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

SKN
  • 11
  • 1
-1

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

Jacob Joy
  • 489
  • 6
  • 7