Skip to content

Latest commit

 

History

History

serverless-with-preexisting-lambda-layer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Upload Lambda layer to AWS

  1. Download the layer zip from Github Releases Step 1
  2. Create a S3 bucket, or use a pre-existing bucket, upload the zip, and copy the URL Step 2
  3. Create a new layer or use a pre-existing layer. (If using a pre-existing layer, Create a new verion) Step 3
  4. Use the S3 file to load into to AWS Lambda Layers Step 4
  5. 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:*

BONUS

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