fgonzalez
fgonzalez

Reputation: 3877

s3 createObject event not being triggered when a file is uploaded to s3

I am using aws serverless to create a function that is called whenever a new file is uploaded to an s3 bucket. I am subscribing like this. Hoever, to test it, I upload the file manually from the amazon console, and I expect the function to be executed, but checking CloudWatch logs, nothing seem to be executed.

If I run the lambda function manually everything works fine and I see the logs in Cloudwatch, however is the event triggering what is failing.

FYI: The bucket is created before than the function in a separate cloud formation stack. So bucket and function are not created at the same time.

Any hints?

register:
    handler: lib/register.handler
    memory: 256
    events:
      - s3:
        bucket: ${self:custom.myBucketArn}
        event: s3:ObjectCreated:*

Upvotes: 1

Views: 1173

Answers (1)

thomasmichaelwallace
thomasmichaelwallace

Reputation: 8464

I'm a bit surprised this manage to deploy, as (unless it's been recently addressed) CloudFormation has a limitation that it can only act on its own resources, which means that Serverless cannot attach triggers to buckets not created by that template.

Luckily this limitation is encountered often enough that people have authored Serverless Framework plugins to workaround it. I recommend you use this plug-in to trigger your lambda on an existing bucket:

https://github.com/matt-filion/serverless-external-s3-event

Upvotes: 2

Related Questions