Automating AWS Lambda Deployments via GitHub Actions and OIDC Authentication
A guide to automating AWS Lambda function deployments from GitHub Actions using OpenID Connect (OIDC) and short-lived IAM roles, eliminating long-lived static access keys from source repositories.
Curated by Vibe DevOps · approx. 469 words
Key Takeaways
- OpenID Connect allows GitHub Actions to assume temporary AWS IAM permissions via AssumeRole without storing long-lived access keys.
- The IAM role trust policy strictly restricts the subject (sub) claim to target branches, preventing unauthorized deployment requests from other repositories.
- Workflow configurations must grant id-token: write permissions to mint GitHub OIDC tokens.
- Polling the update status ensures the pipeline waits for function code updates to complete before initiating version transitions.
From Original Source
Configuring OIDC and Least-Privilege IAM Roles
The automated pipeline consists of three steps: registering GitHub as an OIDC identity provider in AWS IAM, provisioning an IAM role with a trust policy scoped to the repository's target branch, and configuring a workflow to package artifacts and deploy function updates.
IAM policies should follow least privilege, granting only function code update actions rather than broad configuration access. When zip artifact sizes exceed the 50 MB direct upload threshold, the pipeline must stage packages through an S3 bucket or transition to container images.
From Original Source
Update State Management and Deployment Strategies
Lambda function code updates run asynchronously on the cloud infrastructure. Consequently, CI/CD pipelines must include a step to wait for the update state to complete, preventing resource conflicts during rapid, successive deployments.
Beyond publishing immutable versions, engineers can leverage Lambda aliases with weighted routing to execute canary deployments, reducing blast radius and service downtime if issues arise in the new code.
Vibe DevOps Editorial Commentary
Operational Best Practices and Security Governance
Vibe DevOps perspective: Completely eliminating static access keys from repositories is an essential baseline to mitigate credential leakage across CI/CD pipelines. Engineering teams should enforce strict environment separation through branch-level claim conditions.
Pruning development dependencies prior to packaging optimizes deployment artifact size and reduces serverless cold start latencies.
Commands & Configuration Snippets
Verbatim extract for quick lookup. Verify against your infrastructure before running.
npm ci --omit=devInstall production dependencies and remove development packages before packaging
aws lambda wait function-updatedWait for the function code update status to complete before proceeding to the next step
⚠️ Operational Caveats & Limitations
- Applies to standalone function code packaged as zip archives within the direct upload 50 MB threshold.