Prebuilt Sharp AWS Lambda Layer for Node.js 18, 20, and 22. Optimized, bundled, and minified Sharp binaries for x86_64 and arm64 architectures. Improve cold starts with lightweight Sharp builds, ready for Serverless Framework, AWS SAM, and SST deployments.
A pre-built sharp AWS Lambda layer optimized for cold start performance.
- Supports x86_64 and arm64 architectures.
- Compatible with Node.js 18.x, 20.x, and 22.x runtimes.
- Automatically updated and tested using GitHub Actions.
- Bundled and minified with
esbuild
. - Lightweight layer files (~7MB).
- Separate builds for
x64
andarm64
. - Daily checks designed to auto-release on new
sharp
versions. - Optimized for cold starts on AWS Lambda.
- Ideal for use with AWS CDK, AWS SAM, SST and Serverless Framework.
Bundling dependencies and targeting the correct architecture reduces cold start latency dramatically. See Optimizing Node.js dependencies in AWS Lambda for more.
Releases include:
Each file contains a ready-to-use layer for deployment.
import sharp from 'sharp';
Check AWS Lambda Layers documentation.
aws lambda publish-layer-version \
--layer-name sharp-lambda-x64 \
--description "Sharp Layer for x86_64" \
--license-info "Apache-2.0" \
--zip-file fileb://release-x64.zip \
--compatible-runtimes nodejs18.x nodejs20.x nodejs22.x \
--compatible-architectures x86_64
aws lambda publish-layer-version \
--layer-name sharp-lambda-arm64 \
--description "Sharp Layer for arm64" \
--license-info "Apache-2.0" \
--zip-file fileb://release-arm64.zip \
--compatible-runtimes nodejs18.x nodejs20.x nodejs22.x \
--compatible-architectures arm64
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export class MyLambdaStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const sharpLayer = new lambda.LayerVersion(this, 'SharpLayer', {
code: lambda.Code.fromAsset('layers/sharp'),
compatibleArchitectures: [lambda.Architecture.ARM_64],
compatibleRuntimes: [
lambda.Runtime.NODEJS_18_X,
lambda.Runtime.NODEJS_20_X,
lambda.Runtime.NODEJS_22_X,
],
description: 'Sharp Lambda Layer for ARM64',
license: 'Apache-2.0',
});
const myFunction = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.NODEJS_20_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda-handler-directory'),
architecture: lambda.Architecture.ARM_64,
layers: [sharpLayer],
});
}
}
layers: [
new lambda.LayerVersion(stack, "SharpLayer", {
code: lambda.Code.fromAsset("layers/sharp"),
compatibleArchitectures: [lambda.Architecture.ARM_64],
})
]
In your serverless.yml
:
functions:
myFunction:
handler: handler.main
runtime: nodejs20.x
architecture: arm64
layers:
- arn:aws:lambda:us-west-2:123456789012:layer:sharp-v0-34-arm64:1
SharpLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: sharp
ContentUri: layers/sharp/release-arm64.zip
CompatibleArchitectures:
- arm64
CompatibleRuntimes:
- nodejs18.x
- nodejs20.x
- nodejs22.x
Layers are built automatically by GitHub Actions when a new Sharp version is released.
If needed manually:
git clone https://github.com/cbschuld/sharp-aws-lambda-layer.git
cd sharp-aws-lambda-layer
# Follow the GitHub Actions workflows for build instructions.
Released under Apache 2.0 by @cbschuld.