简体   繁体   English

VS Node.js 中 AWS Lambda 函数的清晰图像库

[英]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.我正在 Visual Studio 中处理一个 AWS Lambda 函数,该函数需要快速调整图像大小。 Originally, I was using ImageMagick to resize these images, but the entire process is is taking too long to process.最初,我是使用 ImageMagick 来调整这些图像的大小,但是整个过程处理时间太长。 The alternative to ImageMagick seems to be Sharp, another image library. ImageMagick 的替代品似乎是另一个图像库 Sharp。 Sharp supposedly will use Native AWS Lambda code in order to resize the images faster.据推测,Sharp 将使用原生 AWS Lambda 代码来更快地调整图像大小。 According to this post, Sharp needs to be built in an EC2 instance to do this ( https://github.com/awslabs/serverless-image-resizing ).根据这篇文章,Sharp 需要在 EC2 实例中构建才能执行此操作( 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?如果是这样,是否有为 EC2 内置的 Sharp 预先构建的库,还是我应该自己构建它?

I did find a Sharp library in npm, but I wasn't able to get it to work.我确实在 npm 中找到了一个 Sharp 库,但我无法让它工作。 Is the Sharp library in npm even compatible with AWS Lambda functions? npm 中的 Sharp 库是否与 AWS Lambda 函数兼容? 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 .为了在 AWS Lambda 上为我工作,我能够在我的package.json添加一个 npm 脚本,然后使用npm run dockerbuild -lambda执行npm run dockerbuild 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).这在 Amazon Linux docker 映像上编译,但将输出留在我的项目文件夹中(因此我可以打包 .zip 以部署到 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.npm install docker-lambda之后,我还能够在 docker 镜像中进行测试——因为sharp本机库是为Linux(而不是我的主机系统)编译的,我无法直接测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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