Sharp: Add lambda layers to releases

Created on 2 Jul 2019  路  6Comments  路  Source: lovell/sharp

What are you trying to achieve?

AWS released Lambda Layers to facilitate sharing libraries and binaries across lambda functions.

With Lambda Layers, adopting Sharp.js into any AWS Lambda Node.js project will be a breeze. Plus, there will be less setup, confusion, and errors surrounding compiling for the lambda execution environment.

I appreciate the existing installation instructions for AWS Lambda, and I think Lambda Layers could augment them.

What would you expect the API to look like?

With the releases, also publish the arn of the Lambda Layer for that particular version. This step could be automated into the build process. The docs for installation will need to be updated accordingly.

What alternatives have you considered?

Setting up my own Lambda Layer. Will often be out of date and more error prone.

Building and packaging Sharp.js each time. Build and upload speed will be slower and maintaining versions and consistency across multiple lambda functions will be difficult.

Is there a sample image that helps explain?

N/A. Here are more links about lambda layers:

  • AWS News Announcement (2018)
  • AWS Documentation
  • An issue in this repo describing how to create a Lambda Layer specifically for Sharp.js #1702
  • Links to work done with Lambda Layers and Libvips in Ruby #1657
  • Documentation and build script for creating tarballs for the lambda execution environment

There are other tutorials for creating a Lambda Layer online.

Loving Sharp.js! Just hoping to use it in more places 馃槃

enhancement

Most helpful comment

@jlarmstrongiv There are several solutions on github that generate a layer zip-file with sharp.

I also recently created one with the (currently) latest version - https://github.com/Umkus/lambda-layer-sharp.

All 6 comments

Hello, I'm happy for the docs to link to public, third-party, well-maintained Lambda Layer(s) in the same way there are links to Docker images of a likewise nature.

I'm sure it won't be long before AWS provides a Lambda Layer Marketplace, at which point I might consider providing "official" layers at a small cost.

I regularly take on paid consulting should anyone wish me to create and maintain either private or public Lambda Layers custom to their needs - please feel free to send an email if this would be of interest to you or anyone else reading this.

@exonis any interest in publishing your third-party Lambda Layer? 馃檹

I鈥檓 just a student so I can鈥檛 afford consulting services _yet_ 馃槄

Otherwise, I鈥檒l probably just use the prebuilt tarballs or use a similar build step.

@jlarmstrongiv There are several solutions on github that generate a layer zip-file with sharp.

I also recently created one with the (currently) latest version - https://github.com/Umkus/lambda-layer-sharp.

AWS now provides the "Lambda Layer Marketplace" @lovell: https://serverlessrepo.aws.amazon.com/applications

E.g. imagemagick is on here at https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:145266761615:applications~image-magick-lambda-layer

Using it in a serverless function with the serverless framework is as simple as:

functions:
  genThumbnailFromPNG:
    handler: dist/transform.thumbnailFromPNG
    layers:
      - !GetAtt IMLambdaLayer.Outputs.LayerVersion
    events:
      - s3:
          existing: true
          bucket: ${{env:AWS_S3_MEDIA_BUCKET_NAME}}
          event: s3:ObjectCreated:*
          rules:
            - prefix: public/
            - suffix: screenshot.png

resources:
  Transform: AWS::Serverless-2016-10-31
  Resources:
    IMLambdaLayer:
      Type: AWS::Serverless::Application
      Properties:
        Location:
          ApplicationId: arn:aws:serverlessrepo:us-east-1:145266761615:applications/image-magick-lambda-layer
          SemanticVersion: 1.0.0

Would be great if we can have the same plug-and-play solution with Sharp

I'm looking for a (zip) layer with gif support.
https://github.com/lovell/sharp/pull/2012#issuecomment-567397176

I couldn't do it myself I run into multiple issues with Docker. help appreciated 鉂わ笍

please feel free to send an email if this would be of interest to you or anyone else reading this.

@lovell would you able to reply to my email? I sent it on Thursday. 鉂わ笍

Was this page helpful?
0 / 5 - 0 ratings