Terraform AWS Serverless Modules
Collection of Terraform modules for deploying serverless and container-based applications on AWS, following the Well-Architected Framework.
evergreen#terraform#aws#serverless#ecs#lambda#api-gateway#dynamodb#well-architected
What it is
A collection of 13 reusable Terraform modules for deploying serverless architectures on AWS. Published on the Terraform Registry and available as open source.
The goal is to demonstrate serverless architecture patterns following AWS Well-Architected Framework best practices: security, reliability, operational excellence, performance, and cost optimization.
Modules
| Module | Description |
|---|---|
| vpc | Multi-AZ VPC with NAT gateways, VPC endpoints, flow logs |
| ecr | Container registry with encryption, lifecycle policies, image scanning |
| ecs | Fargate service with auto-scaling, Container Insights, Spot support |
| lambda | Lambda functions with container images, DLQ, retry policies |
| alb | Application Load Balancer with access logs, HTTPS, health checks |
| sqs | FIFO message queues, DLQ, encryption, long polling |
| sns | Pub/sub with Email, SQS, Lambda subscriptions and filtering |
| dynamodb | NoSQL database with encryption, PITR, auto-scaling |
| api-gateway | HTTP API (v2) with throttling, logging, X-Ray |
| api-gateway-v1 | REST API with OpenAPI/Swagger support, VPC Link |
| cloudfront-s3 | CDN + static hosting with SPA routing, OAC |
| waf | Web Application Firewall with rate limiting, IP filtering |
| cloudwatch-alarms | Monitoring for CPU, memory, response time, error rates |
Architecture patterns
ECS with ALB:
graph LR
A[Client] --> B[ALB]
B --> C[ECS Tasks 1-N]
C --> D[ECR]
API Gateway with VPC Link:
graph LR
A[Client] --> B[API Gateway]
B --> C[VPC Link]
C --> D[Private ALB]
D --> E[ECS Tasks]
CRUD API:
graph LR
A[Client] --> B[API Gateway]
B --> C[ECS Fargate]
C --> D[DynamoDB]
A --> E[CloudFront]
E --> F[S3 Static Site]
Usage
module "vpc" {
source = "jonmatum/serverless-modules/aws//modules/vpc"
version = "~> 2.0"
project_name = "my-app"
cidr_block = "10.0.0.0/16"
}
module "ecs" {
source = "jonmatum/serverless-modules/aws//modules/ecs"
version = "~> 2.0"
cluster_name = "my-cluster"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
}Estimated costs
| Environment | Monthly cost | Configuration |
|---|---|---|
| Development | $70-90 | Single NAT, Fargate Spot, 1 task |
| Staging | $150-200 | Single NAT, On-Demand, 2 tasks |
| Production | $200-400 | Multi-AZ NAT, Auto-scaling 2-10 tasks |
Links
- GitHub Repository — Source code for the modules.
- Terraform Registry — Modules published on the official Terraform registry.
- Well-Architected Documentation — Decision mapping to the Well-Architected Framework.