0

In my Serverless YAML file I defined a lambda function with multiple S3 events from different buckets, already existing, such as below

functions:
  my-lambda:
    handler: ...
    name: my-lambda
    description: 'Fetcher'
    environment:
      env_host: aws
    events:
      - s3:
          bucket: bucket1
          existing: true
      - s3:
          bucket: bucket2
          existing: true

The command “serverless deploy” fails with below text:

Only one S3 Bucket can be configured per function. In “my-lambda" you're attempting to configure "bucket1" and "bucket2" at the same time.

Is it possible to configure one lambda with multiple s3 buckets in Serverless?

1 Answer 1

1

Unfortunately no.

From the Serverless doc:

IMPORTANT: You can only attach 1 existing S3 bucket per function.

AWS Lambda allows only one Amazon S3 bucket as an event source. You can define s3 multiple times in events with a different event type but it still must be from the same bucket, see here.

You can though use the handler you wrote multiple times to define multiple functions like this:

functions:
  my-lambda-bucket1:
    handler: ...
    name: my-lambda-bucket1
    description: 'Fetcher with bucket1'
    environment:
      env_host: aws
    events:
      - s3:
          bucket: bucket1
          existing: true
  my-lambda-bucket2:
    handler: ...
    name: my-lambda-bucket2
    description: 'Fetcher with bucket2'
    environment:
      env_host: aws
    events:
      - s3:
          bucket: bucket2
          existing: true
Sign up to request clarification or add additional context in comments.

3 Comments

I see, there is a bug in Serverless. Fixed in the same way, splitting events.
Oh so you can actually note down two different buckets when the events are different?
Yes, since you are deploying 2 functions with same app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.