Skip to content

devandreacarratta/aws-terraform-static-hosting-cloudfront

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AWS Static Hosting with CloudFront

Terraform project for provisioning static website hosting on AWS S3 with CloudFront CDN distribution, Lambda functions, and DynamoDB backend.

Infrastructure Overview

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

Architecture Diagram

Infrastructure Diagram

Project Structure

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

Prerequisites

  • Terraform >= 1.0
  • AWS CLI configured with appropriate credentials
  • An AWS account with permissions to create the required resources

Usage

All Terraform commands should be run from the src/infra directory.

Workspace Setup

Create a new workspace for your environment:

terraform workspace new <environment>

Switch between existing workspaces:

terraform workspace select <environment>

Deploy Infrastructure

Initialize Terraform:

terraform init

To upgrade provider versions:

terraform init -upgrade

Review the execution plan:

terraform plan -var-file="variables/$(terraform workspace show).tfvars"

Apply the configuration:

terraform apply -var-file="variables/$(terraform workspace show).tfvars"

Destroy Infrastructure

terraform destroy -var-file="variables/$(terraform workspace show).tfvars"

Environments

Variable files are located in src/infra/variables/:

  • dev.tfvars - Development environment
  • qa.tfvars - QA environment
  • prod.tfvars - Production environment

Links:

Blog Contents

License

This project is licensed under the MIT License.

About

Terraform project to provision static hosting on AWS S3 and deliver content securely via CloudFront CDN.

Topics

Resources

License

Stars

Watchers

Forks

Contributors