Deploying a dynamic E-commerce Website on AWS Using Terraform

In this short tutorial, I will show you how to deploy an ecommerce website on AWS, how Terraform helps you quickly build and maintain a strong, reliable platform that can grow with your business.

Background

A three-tier architecture is a common framework for building scalable, reliable cloud applications. It breaks the application into three distinct layers, each serving a specific role:

  • Presentation Layer (Web Tier): this layer is responsible for user interaction, managing the user interface (UI/UX), and processing HTTP/S requests and responses.
  • Application Layer (App Tier): this layer handles the core business logic and processes data exchanges between the web and database layers.
  • Data Layer (Database Tier): this layer stores, manages, and retrieves the application’s data, handling queries from the application layer.

This architecture promotes high availability, scalability, and clear separation of responsibilities, making it easier to maintain, scale, and optimize each layer independently.

Project Outline

Deploy an E-commerce Website on AWS in a three tier architecture using Terraform.

Prerequisite

  • Access to AWS account.
  • Install Terraform
  • Familiarity with 3-tier-architecture

Let’s have fun.

Leveraging AWS services and Terraform allow you to efficiently build and maintain a robust, reliable platform that evolves alongside your business.

1. Create main.tf file and connect AWS to Terraform

  • Go to your favorite IDE or open a terminal.
  • Copy and paste the code below. Do not forget to change your profile name.
  • Next, go to AWS S3 console. Create a S3 bucket.

I named my bucket terraform-ecom.

  • Store Terraform state file in your S3 bucket by using the code below.
  • It’s time to initialize our terraform code. Open a new terminal and run terraform init.

2- Create VPC

  • Create two new files named variables.tf and vpc.tf respectively.
  • In the variables.tf file, copy the code below to declare vpc variables.
  • In the vpc.tf file, write your terraform code for vpc resource.

Cheat Sheet: After running your terraform code, verify your AWS if each resource is created correctly

3- Create Internet Gateway resource

  • In the same vpc.tf, add the code lines for internet gateway.

4- Create Public subnet

  • Back to your variables.tf file, create variables for public subnets
  • In your vpc.tf file, add the two public subnets using terraform code.

4- Create Route Table

  • In the same vpc.tf, create route table
  • Associate public subnet to route table

5- Create Private subnet

  • Still in vpc.tf file, complete your terraform code with private subnets
  • It’s time to run terraform plan, then terraform apply.
  • Go back to your AWS console. Verify if all the resources you mentioned in your vpc.tf file have been created.

6- Create Nat gateway

Leverage Terraform to deploy a NAT gateway, allowing outbound traffic from instances within private subnets.

  • Create a natgateway.tf file.
  • Copy and paste the following code lines in your file.
  • After running terraform plan and terraform deploy, you should see Elastic IP address, and Nat gateways deployed in AWS.

7 — Create security groups

8- Create RDS

Use Terraform to set up a Relational Database Service (RDS) for efficient database management.

  • First, create a rds.tf file.
  • Next, create a database subnet group and a database instance.
  • Go to your RDS dashboard and verify if it deployed.
  • Finally, create a certificate manager.

9- Create Application Load Balancer

  • Create alb.tf file
  • create a target group
  • Create a listener on port 80
  • Create a listener on port 443

10- Create a SNS

  • Create a sns.tf file.
  • Copy and paste the code below in the file.
  • Verify if SNS deployed in AWS.

11- Create Auto Scaling Group

Leverage Terraform to create an Auto Scaling Group.

12- Create Record Set in Route 53

  • Create route53.tf file.
  • Create a record set in Route 53

Following these steps will enable you to deploy a secure and scalable e-commerce website on AWS using Terraform. This guide offers a clear and structured process, ensuring that others can easily replicate your deployment.

 

Thank you for reading and/or following along! Leave us a clap or a comment, Share & Follow. Please stay tuned for all my upcoming projects.

Leave a Reply

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