Project : Static Website Deployment

  • Requirement: Deploy a simple static website on AWS.
  • Quick Summary:
    • Uses an S3 bucket to store website files.
    • Configures the S3 bucket for website hosting.
    • Optionally, utilizes a CloudFront distribution for content delivery and edge caching.

Solution (Step by Step):


Step-by-Step Guide

Step 1: Project Setup

  1. Create a Project Directory: Make a new directory for your project (e.g., mkdir static-website-project) and navigate into it (cd static-website-project).
  2. Create a Terraform File: Inside the directory, create a file named This is where we’ll define our infrastructure using Terraform code.

Step 2: S3 Bucket for Website Hosting

  1. Terraform Code – S3 Bucket: Add the following code to your file:
  • Understand the code:
    • The provider block specifies you’re using AWS; update the region accordingly.
    • The resource block creates an S3 bucket, replaces your-unique-bucket-name with something that doesn’t already exist.
    • acl = "public-read" is crucial for website access.
    • The website configuration enables web hosting mode.

2.Initialize Terraform: Run "terraform initin your project directory to initialize Terraform and download provider plugins.

Step 3: Deploy the S3 Bucket

  • Initialize Terraform: In your terminal, navigate to your project directory and run "terraform init“.
  • Plan Your Changes: Run "terraform plan” to see the changes Terraform will make.
  • Apply Changes: Run terraform apply. Type yes when prompted.

Step 4: Create Website Files

  1. Create index.html: Place a basic index.html in your project directory:

2. Upload via AWS CLI:

Step 5: Apply Terraform Configuration

  1. Plan: Run terraform plan to preview the changes.
  2. Apply: Run terraform apply. Type yes to confirm.

Step 6: Test Your Website

  1. Get Website Endpoint: In your terminal output, find “bucket_website_endpoint”. It’ll look like:
  2. Access Website: Open the endpoint URL in a web browser; you should see your website!

Step 7 (Optional): CloudFront Distribution

  1. Terraform Code: Add this to your

2. Apply Changes: Run terraform plan and "terraform apply“.

Step 8: Access Website through CloudFront

  • You’ll find the CloudFront distribution domain name in the AWS CloudFront console, which you can access in your browser.

Important Notes

Congratulations! You’ve successfully deployed a static website on AWS using Terraform. For CloudFront details, refer to AWS documentation.

Terraform : 5 Mini Projects to get Hands-on

Kubernetes : 5 Mini Projects to start with

Hope you find this post helpful.




Leave a Reply

Your email address will not be published. Required fields are marked *

DevOps Lifecycle Simplified Cybersecurity Lifecycle Top 10 Technical Roles for 2023 7 Tips to become Data Scientist