Serverless fails to create a S3 trigger for an existing S3 bucket

Deployment of my serverless app to trigger on S3 events fails to create a S3 trigger to the existing bucket. Below my serverless config. Any ideas what is wrong here? How can one debug this in the serverless framework?

serverless.yml:

...
provider:
  name: aws
  runtime: nodejs12.x
  memorySize: 128 # optional, in MB, default is 1024
  timeout: 10 # optional, in seconds, default is 6
  stage: ${opt:stage, 'dev'}
  region: eu-west-1
  iamRoleStatements:
    - Effect: Allow
      Action:
        - s3:*
      Resource: "*"

functions:
  s3EventProcessor:
    name: s3Importer-${opt:stage}
    handler: handler.processor
    events:
      - s3:
          bucket: upload-test
          event: s3:ObjectCreated:*
          rules:
            - suffix: .csv
          existing: true

Short answer - use GitHub - mayconbordin/serverless-plugin-existing-s3

Long answer - you can’t do what you’re trying to do because S3 bucket triggers are configured as part of the S3 bucket resource in CloudFormation. This means you can only setup S3 bucket triggers if your Lambda and S3 bucket are deployed together. The Serverless framework hides this detail and makes it look like it’s the other direction.

1 Like

Thanks a lot! I just now let Serverless create the bucket and see that the trigger is created. Maybe someone from Serverless can update the docs to let people know using an existing bucket is not a viable option.

1 Like