DEV Community

Harshana vivekanandhan
Harshana vivekanandhan

Posted on

Hosting a Static Website Using S3 in AWS with Terraform

Introduction
Hi there! I've been investigating Terraforms and AWS's capabilities as part of my internship. I recently worked on Hosting a Static Website Using S3 in AWS with Terraform
Hosting a static website on Amazon S3 is a cost-effective and scalable solution that can be easily managed using Terraform. This tutorial will guide you through the steps to set up and deploy a static website using S3 with Terraform.

Prerequisites

Before you begin, ensure you have the following:

  1. AWS Account: If you don’t have one, create it here.
  2. Terraform Installed: Download and install Terraform from the official site.
  3. AWS CLI Configured: Install and configure the AWS CLI. Follow the instructions here.

Step-by-Step Guide

1. Set Up Your Terraform Project

  1. Create a Directory: Start by creating a directory for your Terraform project.
  2. Create the main.tf File: This file will contain the Terraform configuration for your S3 static website.

2. Initialize Terraform

Run the following command to initialize your Terraform project:

3. Plan the Deployment

Run the terraform plan command to see what Terraform will do:

4. Apply the Configuration

Apply the configuration to create the S3 bucket and upload the website files:
Terraform will prompt for confirmation. Type yes to proceed.

5. Verify the Deployment

Once the apply command completes, Terraform will output the website URL. You can access your static website using this URL.

Conclusion

Using Terraform to host a static website on Amazon S3 simplifies the deployment and management process. With infrastructure as code, you can version, reproduce, and maintain your static websites more efficiently. This guide provides a foundational setup, which you can expand upon by adding more resources and configurations as needed.By leveraging Terraform and AWS S3, you can quickly deploy scalable and reliable static websites, making your web hosting process smoother and more efficient.

Top comments (0)