This document outlines a plan of approach for automating deployment of AWS Lambda functions using Terraform and Github Actions.
Terraform manages infrastructure and GitHub Actions manages code deployments.
Goal: As a BRANCH dev, I want to be able to have automatic builds and deployed Lambdas when I push to main / edit Lambdas.
Separation of Concerns:
Benefits:
┌─────────────────────────────────────────────────────────────┐
│ Initial Setup (One-Time) │
│ │
│ 1. Terraform Apply │
│ ├─ Creates Lambda functions with placeholder code │
│ ├─ Creates S3 bucket for deployments │
│ ├─ Creates IAM role for Lambda execution │
│ └─ Configures environment variables │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ First Deployment (GitHub Actions) │
│ │
│ 1. Build: npm ci + npm run build │
│ 2. Package: Copy node_modules + create zip file │
│ 3. Upload: Upload zip to S3 with timestamp │
│ 4. Update: aws lambda update-function-code │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Future Updates (GitHub Actions) │
│ │
│ Same process as first deployment │
│ Terraform ignores s3_key changes (lifecycle block) │
└─────────────────────────────────────────────────────────────┘