- Download the layer zip from Github Releases
- Create a S3 bucket, or use a pre-existing bucket, upload the zip, and copy the URL
- Create a new layer or use a pre-existing layer. (If using a pre-existing layer, Create a new verion)
- Use the S3 file to load into to AWS Lambda Layers
- Add the layer to your serverless function
service: sls-with-preexisting-layer
provider:
name: aws
runtime: nodejs18.x
stage: dev
region: us-east-1
timeout: 300
functions:
chromium-test:
handler: index.handler
layers:
- arn:aws:lambda:us-east-1:************:layer:chromium:*
These steps can easily be automated using the following code:
$ chromiumVersion="112.0.0"
$ bucketName="chromiumUploadBucket"
$ wget "https://github.com/Sparticuz/chromium/releases/download/v${chromiumVersion}/chromium-v${chromiumVersion}-layer.zip"
$ aws s3 cp "chromium-v${chromiumVersion}-layer.zip" "s3://${bucketName}/chromiumLayers/chromium-v${chromiumVersion}-layer.zip"
$ aws lambda publish-layer-version --layer-name chromium --description "Chromium v${chromiumVersion}" --content "S3Bucket=${bucketName},S3Key=chromiumLayers/chromium-v${chromiumVersion}-layer.zip" --compatible-runtimes nodejs --compatible-architectures x86_64