Terraform project for provisioning static website hosting on AWS S3 with CloudFront CDN distribution, Lambda functions, and DynamoDB backend.
This project provisions the following AWS resources:
| Resource | Description |
|---|---|
| S3 Bucket | Static website hosting |
| CloudFront Distribution | Global CDN with HTTPS support |
| DynamoDB Table | Product data storage |
Lambda Function (get_products) |
Read items from DynamoDB |
Lambda Function (post_products) |
Write items to DynamoDB |
src/
├── infra/ # Terraform configuration files
│ └── variables/ # Environment-specific tfvars files
├── infra-modules/ # Reusable Terraform modules
│ ├── dynamodb_table/
│ ├── iam_role_policy/
│ ├── lambda_function/
│ ├── lambda_function_url/
│ ├── s3_bucket_private/
│ ├── s3_object/
│ └── s3_object_template/
├── lambda-function-python/ # Python source code for Lambda functions
├── lambda-function-python-zip/ # Generated Lambda deployment packages
└── web-template/ # Static web assets for S3
- Terraform >= 1.0
- AWS CLI configured with appropriate credentials
- An AWS account with permissions to create the required resources
All Terraform commands should be run from the src/infra directory.
Create a new workspace for your environment:
terraform workspace new <environment>Switch between existing workspaces:
terraform workspace select <environment>Initialize Terraform:
terraform initTo upgrade provider versions:
terraform init -upgradeReview the execution plan:
terraform plan -var-file="variables/$(terraform workspace show).tfvars"Apply the configuration:
terraform apply -var-file="variables/$(terraform workspace show).tfvars"terraform destroy -var-file="variables/$(terraform workspace show).tfvars"Variable files are located in src/infra/variables/:
dev.tfvars- Development environmentqa.tfvars- QA environmentprod.tfvars- Production environment
This project is licensed under the MIT License.
