Lambda Deployment Guide

Overview

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.



Architecture & Approach

Approach:

Separation of Concerns:

Benefits:

  1. Fast Deployments: Code changes don't require Terraform runs
  2. Infrastructure as Code: All infrastructure is version-controlled and reproducible
  3. CI/CD Integration: Automatic deployments on code changes
  4. Rollback Capability: S3 versioning enables easy rollbacks
  5. No Conflicts: Terraform and CI/CD don't interfere with each other

How It Works

┌─────────────────────────────────────────────────────────────┐
│ 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)          │
└─────────────────────────────────────────────────────────────┘