A modular Terraform project for deploying AWS Lambda functions with API Gateway, IAM roles, and CloudWatch log groups. Supports environment separation and reusable infrastructure components.
Design Overview:
- User requests go to API Gateway (HTTP API)
- API Gateway triggers the Lambda function
- Lambda writes logs to CloudWatch Log Group and assumes the IAM Role for permissions
- All resources are managed as separate, reusable modules
modules/
iam-role/
main.tf
cloudwatch-log-group/
main.tf
lambda-function/
main.tf
api-gateway/
main.tf
env/
main.tf
variables.tf
- Terraform >= 1.0
- AWS credentials configured (via environment variables, AWS CLI, or credentials file)
- Clone the repository:
git clone https://github.com/bushmusi/terraform-aws-modular-lambda-api.git cd terraform-aws-modular-lambda-api
- Review and customize variables:
- Edit
env/variables.tf
to set your desired values (e.g., Lambda name, tags, etc.)
- Edit
- Add your Lambda deployment package:
- Place your
lambda_function_payload.zip
in the project root or update the path in the module if needed.
- Place your
- Initialize Terraform:
cd env terraform init
- Plan and apply:
terraform plan terraform apply
- Destroy (when done):
terraform destroy
- You can add more environments by copying the
env
directory and adjusting variables. - Each module is reusable and can be extended for more advanced use cases.
- GitHub: bushmusi
- LinkedIn: Bushra Mustofa