Default Parameter Values for S3 Events

I have an resize lambda, triggered by a S3 objectCreated event, which I was hoping I could pass some parameters through the serverless.yml file to resize a bunch of times into different sizes. I’m not sure if this is possible right now using only one handler.

Is it possible to have a triggered lambda with some default parameter values such as ‘width = 1024, height = 768’

Currently my code is as follows:

  resize:
    handler: resize.resize
    events:
      - s3:
          bucket: my-photos
          event: s3:ObjectCreated:*
          rules:
            - prefix: original/
            - suffix: .jpg

I was hoping to have a few of these exact blocks but with different sizes being passed.

Thanks!

Did you try environments with handler?

  resize:
    handler: resize.resize
    environment:
        width: 1024
        height: 768 
    events:
      - s3:
          bucket: my-photos
          event: s3:ObjectCreated:*
          rules:
            - prefix: original/
            - suffix: .jpg

In your lambda handler resize.resize, there should be codes as below to get these environments

  const params = {
    width: process.env.width,
    height: process.env.height,
    Item: {
      ...
    }
  }
1 Like

Thanks mate, will try this now. I also assumed you meant proper json width: 1024 ?

updated.

Does it work?

Yep, all good, thanks for the suggestion. Legend!