11# AWS Sharp Lambda Layer (x86\_ 64 and arm64)
22
3- [ ![ GitHub tag] ( https://img.shields.io/github/tag/cbschuld/sharp-aws-lambda-layer?include_prereleases=&sort=semver&color=blue )] ( https://github.com/cbschuld/sharp-aws-lambda-layer/releases/ )
3+ [ ![ Build Layers] ( https://github.com/cbschuld/sharp-aws-lambda-layer/workflows/Build%20Layers/badge.svg )] ( https://github.com/cbschuld/sharp-aws-lambda-layer/actions?query=workflow:"Build+Layers" )
4+ [ ![ GitHub release] ( https://img.shields.io/github/release/cbschuld/sharp-aws-lambda-layer?include_prereleases=&sort=semver&color=blue )] ( https://github.com/cbschuld/sharp-aws-lambda-layer/releases/ )
45[ ![ License] ( https://img.shields.io/badge/License-Apache_2.0-blue )] ( #license )
5- [ ![ Build ] ( https://github.com/ cbschuld/sharp-aws-lambda-layer/workflows/Build%20Layers/badge.svg )] ( https://github.com/cbschuld/sharp-aws-lambda-layer/actions?query=workflow:"Build%20Layers" )
6+ [ ![ issues - sharp-aws-lambda-layer ] ( https://img.shields.io/github/issues/ cbschuld/sharp-aws-lambda-layer )] ( https://github.com/cbschuld/sharp-aws-lambda-layer/issues )
67
78Prebuilt 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.
89
@@ -21,7 +22,7 @@ A pre-built [sharp](https://www.npmjs.com/package/sharp) AWS Lambda layer optimi
2122- Separate builds for ` x64 ` and ` arm64 ` .
2223- Daily checks designed to auto-release on new ` sharp ` versions.
2324- Optimized for cold starts on AWS Lambda.
24- - Ideal for use with AWS SAM, SST and Serverless Framework.
25+ - Ideal for use with AWS CDK, AWS SAM, SST and Serverless Framework.
2526
2627## Why Separate Builds?
2728
@@ -69,6 +70,40 @@ aws lambda publish-layer-version \
6970 --compatible-architectures arm64
7071```
7172
73+ ### AWS CDK Usage Example
74+
75+ ``` typescript
76+ import * as lambda from ' aws-cdk-lib/aws-lambda' ;
77+ import { Stack , StackProps } from ' aws-cdk-lib' ;
78+ import { Construct } from ' constructs' ;
79+
80+ export class MyLambdaStack extends Stack {
81+ constructor (scope : Construct , id : string , props ? : StackProps ) {
82+ super (scope , id , props );
83+
84+ const sharpLayer = new lambda .LayerVersion (this , ' SharpLayer' , {
85+ code: lambda .Code .fromAsset (' layers/sharp' ),
86+ compatibleArchitectures: [lambda .Architecture .ARM_64 ],
87+ compatibleRuntimes: [
88+ lambda .Runtime .NODEJS_18_X ,
89+ lambda .Runtime .NODEJS_20_X ,
90+ lambda .Runtime .NODEJS_22_X ,
91+ ],
92+ description: ' Sharp Lambda Layer for ARM64' ,
93+ license: ' Apache-2.0' ,
94+ });
95+
96+ const myFunction = new lambda .Function (this , ' MyFunction' , {
97+ runtime: lambda .Runtime .NODEJS_20_X ,
98+ handler: ' index.handler' ,
99+ code: lambda .Code .fromAsset (' lambda-handler-directory' ),
100+ architecture: lambda .Architecture .ARM_64 ,
101+ layers: [sharpLayer ],
102+ });
103+ }
104+ }
105+ ```
106+
72107### SST Usage Example
73108
74109``` javascript
@@ -80,6 +115,20 @@ layers: [
80115]
81116```
82117
118+ ### Serverless Framework Usage Example
119+
120+ In your ` serverless.yml ` :
121+
122+ ``` yaml
123+ functions :
124+ myFunction :
125+ handler : handler.main
126+ runtime : nodejs20.x
127+ architecture : arm64
128+ layers :
129+ - arn:aws:lambda:us-west-2:123456789012:layer:sharp-v0-34-arm64:1
130+ ` ` `
131+
83132### AWS SAM Usage Example
84133
85134` ` ` yaml
@@ -110,11 +159,10 @@ cd sharp-aws-lambda-layer
110159
111160## License
112161
113- Apache License 2.0 - [ http://www.apache.org/licenses/LICENSE-2.0 ] ( http ://www.apache.org/licenses/LICENSE-2.0 )
162+ Released under [ Apache 2.0] ( /LICENSE ) by [ @ cbschuld ] ( https ://github.com/cbschuld ) .
114163
115164## References
116165
117166- [ Sharp Installation Guide] ( https://sharp.pixelplumbing.com/install#aws-lambda )
118167- [ AWS Lambda Layers] ( https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html )
119168- [ Optimizing Node.js Dependencies in Lambda] ( https://aws.amazon.com/blogs/compute/optimizing-node-js-dependencies-in-aws-lambda/ )
120-
0 commit comments