How to Deploy API Gateway and Lambda With GitHub Actions
Update the backing Lambda, then publish the API to its stage with aws apigateway create-deployment.
After updating the Lambda code, promote the REST API changes to a stage with aws apigateway create-deployment --rest-api-id --stage-name. SAM or CloudFormation is cleaner for full provisioning; this targets an existing API.
Steps
- Update the backing Lambda function code.
- Authenticate to AWS over OIDC.
- Run
aws apigateway create-deploymentfor the REST API and stage. - Verify with a request to the stage invoke URL.
Workflow
.github/workflows/deploy.yml
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: zip -r function.zip index.js
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-apigw-deploy
aws-region: us-east-1
- run: |
aws lambda update-function-code \
--function-name api-handler --zip-file fileb://function.zip
aws apigateway create-deployment \
--rest-api-id abc123xyz --stage-name prodGotchas
- New routes or integrations require an API redeploy; a Lambda update alone is not enough.
- HTTP APIs (v2) with auto-deploy stages do not need an explicit create-deployment call.
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 Deploy With AWS SAM in GitHub ActionsBuild and deploy a serverless application with AWS SAM from GitHub Actions using sam build and sam deploy in…