Skip to content

Monorepo for multiple AWS Lambda functions with Terraform and a single API Gateway HTTP API.

Notifications You must be signed in to change notification settings

pnstack/aws-function-template

Repository files navigation

Lambda Monorepo Template

Monorepo for multiple AWS Lambda functions with Terraform and a single API Gateway HTTP API.

Requirements

  • Node.js >= 18
  • Terraform >= 1.5
  • AWS CLI configured
  • Language toolchains as needed:
    • TypeScript/JavaScript: Node + npm
    • Python: python3 + pip
    • Go: Go 1.22+
    • Java: JDK 17 + Maven
    • Rust: Rust 1.74+ with aarch64-unknown-linux-gnu target

Repo Structure

  • functions/<function_name>/
    • function.json (runtime, handler, env, routes)
    • src/ (handler code)
    • language build files (package.json, tsconfig.json, requirements.txt, go.mod, pom.xml)
  • templates// (starter templates)
  • infra/ (Terraform)
  • scripts/ (build/package/deploy helpers)

Create a Function

  1. Copy a template:
    • cp -R templates/ts functions/my-ts
  2. Edit function config:
    • functions/my-ts/function.json
  3. Implement handler in functions/my-ts/src/

Build & Package

Package all functions:

  • bash scripts/package.sh

Package a single function:

  • bash scripts/package.sh my-ts

Sync Terraform Functions

Generate infra/functions.auto.tfvars.json from all function.json files:

  • node scripts/sync-terraform.js

Deploy (Terraform)

Packages all functions, syncs Terraform inputs, then applies:

  • bash scripts/deploy.sh

Pass terraform flags:

  • bash scripts/deploy.sh -var 'enable_http_api=true'

Invoke

Local (Node only):

  • bash scripts/invoke-local.sh hello-ts

Remote via API Gateway:

  • bash scripts/invoke-remote.sh hello-ts /hello-ts

Logs:

  • bash scripts/tail-logs.sh hello-ts

Terraform Inputs

Edit infra/terraform.tfvars for shared settings:

  • aws_region
  • project_name
  • enable_http_api
  • enable_function_url

Function-specific settings come from:

  • functions//function.json

Notes

  • API Gateway routes are defined per function via function.json routes.
  • Go functions use provided.al2023 and a bootstrap binary.
  • Rust functions use provided.al2023 and a bootstrap binary.
  • Packaging produces dist/<function_name>.zip for Terraform.

About

Monorepo for multiple AWS Lambda functions with Terraform and a single API Gateway HTTP API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published