DEV Community

Cover image for Creating a Multi-Tier Architecture with S3, EC2, and RDS: A Step-by-Step Guide
Oluwaseun Olaleye
Oluwaseun Olaleye

Posted on

Creating a Multi-Tier Architecture with S3, EC2, and RDS: A Step-by-Step Guide

USE CASE
As a newly employed cloud engineer, I have been asked to create a multi-tier architecture. This architecture should consist of a website where HTML files can be stored and have an API to handle client requests. Additionally, I want to ensure that when we build our website, every user globally has the same experience, with minimal delay.

Image description

Introduction

Welcome to our comprehensive guide on building a scalable and secure multi-tier architecture using Amazon S3, EC2, and RDS. In this article, I will walk you through each step, explaining the process in detail.

Prerequisites

Before we begin, let's review the prerequisites:

  1. Simple Storage Service (S3): Stores static assets (HTML, CSS, JavaScript, images, videos) and hosts your static website.
  2. Elastic Compute Cloud (EC2): Runs web server software, handles HTTP requests, and processes dynamic content.
  3. Relational Database Service (RDS): Stores sensitive and structured data as a backup.
  4. CloudFront: A content delivery network (CDN) that distributes website content globally, reducing latency and improving performance.

Let's Dive into EC2

As we all know, EC2 is a web server. In our multi-tier architecture, this EC2 instance will serve as an API that collects client requests. Ec2 helps you to secure and scalable server to host your web Application

Step 1: Launch an EC2 Instance

Step 2: Choose Amazon Machine Image (AMI)

Image description

Step 3: Select Instance Type

Choose the right instance type for your workload.
Step 4: Create a Key Pair

Generate a secure key pair for SSH access.
A key pair is important because;

  • Ensures secure SSH access.
  • Protects your instance from unauthorized access.

Image description

Step 5: Click on Launch instance.

Image description

INTRODUCTION TO AMAZON RDS
Amazon Relational Database Service supports automatic failover and automated backups. This ensures you can handle data loss or downtime because of hardware failure. The database provides high availability and scalability for your application. We want our website to be available at every time and that is why we are introducing RDS. Let's create RDS, this will be connected to EC2.

Image description

Image description

Image description

Image description

Image description

Now that we have created our RDS, let install some packages.

Image description

Image description

Image description

Now let's create S3 Bucket for storage.

Image description

Step 2:Give our bucket a name and unchecked the public asset. We want our website to be accessible publicly.

Image description

Image description

We will leave everything at default and create our bucket.

Image description

Let's go ahead and click on the bucket we just created, what next is to upload our HTML file to S3.

Image description

Image description

Image description

Next thing is to configure S3 Bucket Policy: Define permissions for bucket access.

Image description

Image description

Image description

Let's enable static website and copy the URL and viola our website is life but we are not done yet.

Image description

Image description

Image description

Image description

Image description

We are going to copied the URL for our website and paste to a browser.

Image description

Let's Create IAM Role for EC2-S3 Connection : This is to establish secure communication between EC2 and S3.As earlier said, the EC2 will serve as API that collects client request.

Let's create IAM role that we be attached to EC2.

Image description

Image description
Image description.

The role has been created, let go ahead and click on the role created and attached permission to it.

Image description

Image description

We want this role to have access to our S3, so we select S3 for "service"

Image description

Image description

Image description

Note: Kindly put the bucket ARN to all the permission under resource.

Now that we have created our role, let's assign the IAM role to EC2 instance that was created.

Image description

Image description
Let's connect to the EC2 instance and run some commands.

Image description

Introduce CloudFront:
Now let's dive in.
Like we said earlier, we want our users globally to be able to access our website within a minimum TTL. The website will be cached so that users can access it within a minimized time.

Image description

Let's copied our static website URL and copied it to the origin domain.

Image description

Image description

Image description

Image description

Let's Copy the distribution and paste it to a browser, it's going to direct us to our website.

Image description
.
Conclusion

Congratulations! You have successfully created a multi-tier architecture using S3, EC2, and RDS. This scalable and secure architecture will host your web application, store static assets, and distribute content globally.

Top comments (0)