我启动了最新的 aws linux 并运行了以下命令。
yum -y install gcc-c++ libpng-devel libjpeg-devel libtiff-devel wget
wget https://downloads.sourceforge.net/project/graphicsmagick/graphicsmagick/1.3.26/GraphicsMagick-1.3.26.tar.gz
tar zxvf GraphicsMagick-1.3.26.tar.gz
cd GraphicsMagick-1.3.26
./configure --prefix=/var/task/graphicsmagick --enable-shared=no --enable-static=yes
make
sudo make install
tar zcvf ~/graphicsmagick.tgz /var/task/graphicsmagick/
我将目录复制到本地并将其放入要压缩和部署的包中。我的布局类似于链接的 aws 存储库代码,但针对无服务器进行了修改。
拉姆达代码:
// graphicsmagick dir is at the root of my project
const BIN_PATH = process.env['LAMBDA_TASK_ROOT'] + "/graphicsmagick/bin/";
const Gm = require('gm').subClass({ appPath: BIN_PATH });
// below is inside the handler
process.env['PATH'] = process.env['PATH'] + ':' + BIN_PATH;
无服务器.yml
package:
artifact: /path/to/function.zip
我使用该工件并构建了我自己的 zip。如果您遇到以下问题,我建议您这样做。https://github.com/serverless/serverless/issues/3215 https://github.com/serverless/serverless/issues/3215
# -y to keep the symlinks and thus reduce the size from 266M to 73M
cd lambda && zip -FS -q -r -y ../dist/function.zip *
想法来自:
https://gist.github.com/bensie/56f51bc33d4a55e2fc9a https://gist.github.com/bensie/56f51bc33d4a55e2fc9a
https://github.com/awslabs/serverless-image-resizing https://github.com/awslabs/serverless-image-resizing
编辑:
可能还想查看拉姆达层 https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html。这种事情可能只需要做一次。