简体   繁体   中英

Sharp image library for AWS Lambda functions in VS Node.js

I'm working on an AWS Lambda function in Visual Studio that calls for fast image resizing. Originally, I was using ImageMagick to resize these images, but the entire process is is taking too long to process. The alternative to ImageMagick seems to be Sharp, another image library. Sharp supposedly will use Native AWS Lambda code in order to resize the images faster. According to this post, Sharp needs to be built in an EC2 instance to do this ( https://github.com/awslabs/serverless-image-resizing ).

I haven't been able to get this to work yet. Has anyone here got this to work yet? If so, is there a pre-built library out there for Sharp built in EC2 or should I build it myself?

I did find a Sharp library in npm, but I wasn't able to get it to work. Is the Sharp library in npm even compatible with AWS Lambda functions? If so, does it have the increased speed by using native processing?

To get sharp to work for me on AWS Lambda, I was able to add an npm script in my package.json and then do a npm run dockerbuild using docker-lambda . This compiled on the Amazon Linux docker image, but left the outputs was in my project folder (so I could package the .zip for deployment to AWS Lambda).

  "scripts": {
    "dockerbuild": "docker run -v \"$PWD\":/var/task lambci/lambda:build-nodejs6.10"
  },

I was also able to test inside the docker image after npm install docker-lambda - since the sharp native library was compiled for Linux (and not my host system), I could not test directly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM