|
| 1 | +# AWS Sharp layer |
| 2 | + |
| 3 | +This AWS lambda layer contains a pre-built [sharp](https://www.npmjs.com/package/sharp) **v0.32 (Flow)** npm library. |
| 4 | +It is optimized for the most frugal space usage possible. Includes support for Node 16 and Node 18. |
| 5 | + |
| 6 | +## Dependencies |
| 7 | + |
| 8 | +- Docker |
| 9 | + |
| 10 | +## AWS Server - Installs |
| 11 | + |
| 12 | +```sh |
| 13 | +sudo yum install docker git wget curl |
| 14 | +sudo systemctl start docker |
| 15 | +``` |
| 16 | + |
| 17 | +# AWS Repository Description |
| 18 | + |
| 19 | +This serverless application provides a Lambda Layer that includes the [sharp](https://sharp.pixelplumbing.com/) image processing library for Node.js. The original work is from Paul Spencer, this is a fork of his work but with Node16.x, Node 18.x & v0.32 (flow) |
| 20 | + |
| 21 | +The motivation for this layer is two-fold: |
| 22 | + |
| 23 | +You need to bundle the x86 binaries for libvips with sharp when installing it, this is difficult on MacOS |
| 24 | +The library size is big enough to make the function not editable in the Lambda console. To use this layer in a Node.js lambda function, simply add this layer to your stack. The published version of this layer will track the version of sharp that is available. |
| 25 | + |
| 26 | +# AWS Repository License |
| 27 | + |
| 28 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 29 | + |
| 30 | +# Getting |
| 31 | + |
| 32 | +A pre-built layer zip file is available on the [Releases page](../../releases), alongside the size of the layer. |
| 33 | + |
| 34 | +# Building |
| 35 | + |
| 36 | +## Steps |
| 37 | + |
| 38 | +1. Clone the repo: |
| 39 | + ```shell script |
| 40 | + git clone git@github.com:cbschuld/sharp-aws-lambda-layer.git |
| 41 | + cd sharp-aws-lambda-layer/ |
| 42 | + ``` |
| 43 | +1. Install dependencies: |
| 44 | + ```shell script |
| 45 | + docker run -v "$PWD":/var/task public.ecr.aws/sam/build-nodejs18.x:latest npm --no-optional --no-audit --progress=false install |
| 46 | + ``` |
| 47 | +1. Build the layer: |
| 48 | + ```shell script |
| 49 | + docker run -v "$PWD":/var/task public.ecr.aws/sam/build-nodejs18.x:latest node ./node_modules/webpack/bin/webpack.js |
| 50 | + ``` |
| 51 | +1. Perform a smoke-test: |
| 52 | + ```shell script |
| 53 | + docker run -w /var/task/dist/nodejs -v "$PWD":/var/task public.ecr.aws/sam/build-nodejs18.x:latest node -e "console.log(require('sharp'))" |
| 54 | + ``` |
| 55 | +1. Import created layer into your AWS account: |
| 56 | + ```shell script |
| 57 | + aws --profile=tintable lambda publish-layer-version --layer-name sharp-v0-32 --description "Sharp layer - v0.32 (Flow)" --license-info "Apache License 2.0" --zip-file fileb://sharp-layer-v0-32.zip --compatible-runtimes nodejs16.x nodejs18.x --compatible-architectures x86_64 |
| 58 | + ``` |
0 commit comments