1
1
# AWS Sharp Lambda Layer (x86\_ 64 and arm64)
2
2
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/ )
4
5
[ ![ License] ( https://img.shields.io/badge/License-Apache_2.0-blue )] ( #license )
5
- [ ![ Build ] ( https://github.com/ cbschuld/sharp-aws-lambda-layer/workflows/Build%2
10000
0Layers/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 )
6
7
7
8
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.
8
9
@@ -21,7 +22,7 @@ A pre-built [sharp](https://www.npmjs.com/package/sharp) AWS Lambda layer optimi
21
22
- Separate builds for ` x64 ` and ` arm64 ` .
22
23
- Daily checks designed to auto-release on new ` sharp ` versions.
23
24
- 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.
25
26
26
27
## Why Separate Builds?
27
28
@@ -69,6 +70,40 @@ aws lambda publish-layer-version \
69
70
--compatible-architectures arm64
70
71
```
71
72
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
+
72
107
### SST Usage Example
73
108
74
109
``` javascript
@@ -80,6 +115,20 @@ layers: [
80
115
]
81
116
```
82
117
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
+
83
132
### AWS SAM Usage Example
84
133
85
134
` ` ` yaml
@@ -110,11 +159,10 @@ cd sharp-aws-lambda-layer
110
159
111
160
## License
112
161
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 ) .
114
163
115
164
## References
116
165
117
166
- [ Sharp Installation Guide] ( https://sharp.pixelplumbing.com/install#aws-lambda )
118
167
- [ AWS Lambda Layers] ( https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html )
119
168
- [ Optimizing Node.js Dependencies in Lambda] ( https://aws.amazon.com/blogs/compute/optimizing-node-js-dependencies-in-aws-lambda/ )
120
-
0 commit comments