Serverless API
Build a serverless API using Lambda and API Gateway with Patterned Designs modules.
This guide demonstrates how to build a serverless API using AWS Lambda and related services.
What You’ll Build
- Lambda functions for API endpoints
- IAM roles with least-privilege permissions
- Secrets management for API keys
Prerequisites
- Completed Getting Started
- AWS credentials with Lambda and IAM permissions
Modules Used
- lambda-function - Serverless compute
- iam-role - Identity and access
- secrets-manager - Secret storage
Implementation
Step 1: Create the IAM Role
module "lambda_role" {
source = "registry.patterneddesigns.ca/patterneddesigns/iam-role/aws"
version = "1.0.0"
name = "api-lambda-role"
}
Step 2: Store Secrets
module "api_secrets" {
source = "registry.patterneddesigns.ca/patterneddesigns/secrets-manager/aws"
version = "1.0.0"
name = "api-credentials"
}
Step 3: Deploy Lambda Function
module "api_handler" {
source = "registry.patterneddesigns.ca/patterneddesigns/lambda-function/aws"
version = "1.0.0"
name = "api-handler"
role_arn = module.lambda_role.role_arn
}
Complete Example
See the full working example in the examples directory.
Next Steps
- VPC with EC2 - Build traditional infrastructure
- Security Best Practices - Secure your serverless apps