How to Publish a Lambda Layer With GitHub Actions
Zip the layer contents under the correct path, publish a new layer version, then attach it to your function.
Package the dependencies in the layer directory layout (for example nodejs/node_modules), aws lambda publish-layer-version, then attach the returned ARN with update-function-configuration --layers.
Steps
- Install dependencies under the layer path (e.g.
nodejs/node_modules). - Zip that directory into
layer.zip. - Run
aws lambda publish-layer-versionand capture the version ARN. - Attach it with
aws lambda update-function-configuration --layers.
Workflow
.github/workflows/deploy.yml
permissions:
id-token: write
contents: read
jobs:
layer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
mkdir -p nodejs && cp package*.json nodejs/
(cd nodejs && npm ci --omit=dev)
zip -r layer.zip nodejs
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-layer-publish
aws-region: us-east-1
- run: |
ARN=$(aws lambda publish-layer-version \
--layer-name shared-deps \
--zip-file fileb://layer.zip \
--compatible-runtimes nodejs20.x \
--query 'LayerVersionArn' --output text)
aws lambda update-function-configuration \
--function-name my-fn --layers "$ARN"Gotchas
- The directory layout matters: Node layers must use
nodejs/node_modules, Python usespython/. - Each publish creates a new version; functions pin a specific version ARN, not "latest".
Related guides
How to Deploy a Zip Lambda Function With GitHub ActionsPackage and deploy an AWS Lambda function as a zip from GitHub Actions using OIDC and aws lambda update-funct…
How to Do a Canary Lambda Deploy With Aliases in GitHub ActionsShift traffic gradually to a new Lambda version from GitHub Actions using a weighted alias, publishing a vers…