How to Deploy With AWS SAM in GitHub Actions
Run sam build then sam deploy with non-interactive flags so the changeset applies without prompts.
Install the SAM CLI with aws-actions/setup-sam, authenticate with OIDC, then run sam build and sam deploy --no-confirm-changeset --no-fail-on-empty-changeset. SAM provisions Lambda, API Gateway, and related resources via CloudFormation.
Steps
- Install the SAM CLI with
aws-actions/setup-sam. - Authenticate to AWS over OIDC.
- Run
sam build. - Run
sam deploywith--no-confirm-changesetand--no-fail-on-empty-changeset.
Workflow
.github/workflows/deploy.yml
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: aws-actions/setup-sam@v2
with:
use-installer: true
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-sam-deploy
aws-region: us-east-1
- run: sam build
- run: |
sam deploy \
--stack-name my-app \
--capabilities CAPABILITY_IAM \
--resolve-s3 \
--no-confirm-changeset \
--no-fail-on-empty-changesetGotchas
--resolve-s3lets SAM manage its own artifact bucket; otherwise pass--s3-bucket.- Stacks that create named IAM resources need
CAPABILITY_NAMED_IAM.
Related guides
How to Deploy API Gateway and Lambda With GitHub ActionsDeploy a Lambda-backed REST API and stage to Amazon API Gateway from GitHub Actions by updating the function…
How to Deploy a CloudFormation Stack With GitHub ActionsDeploy or update an AWS CloudFormation stack from GitHub Actions with aws cloudformation deploy, passing para…