navigation

Workshop: Deploying a Fullstack Blog Website on AWS EC2 with DocumentDB, CloudFront & S3

Overview

In this workshop, you will learn how to deploy a Fullstack Blog Website on AWS using EC2, leverage DocumentDB as a NoSQL database, and optimize performance and costs with CloudFront.

Workshop Architecture

Objectives:

  • Understand how to create and configure EC2, DocumentDB, CloudFront, and IAM on AWS.
  • Learn how to deploy a MERN fullstack blog application on EC2.
  • Connect and interact with DocumentDB from EC2, including data migration from MongoDB to DocumentDB.
  • Configure CloudFront to offload traffic from EC2 and enhance performance.
  • Manage access control between AWS services using IAM.

Prerequisites:

  • An AWS account with IAM access permissions.
  • A computer with an SSH client (e.g., Terminal or PuTTY).

AWS Services and Costs

1. Amazon EC2 (Elastic Compute Cloud) Purpose:

  • Amazon EC2 is used to host the backend application, process data, and connect to Amazon DocumentDB for querying.
  • The EC2 instance is placed in a Public Subnet to allow communication with the internet via an Internet Gateway.

Cost:

StatusInstance TypeDaily CostMonthly Cost
Free Tiert2.micro (750 free hours)$0.00$0.00
Beyond Free Tiert2.micro (~$0.30/day)$0.30~$9

2. Amazon DocumentDB Purpose:

  • DocumentDB serves as a NoSQL database for storing and managing data.
  • Two DocumentDB instances are placed in different Private Subnets for high availability and data replication.

Cost:

StatusInstance TypeDaily CostMonthly Cost
Free Tierdb.t3.medium (750 free hours)$0.00$0.00
Beyond Free Tierdb.t3.medium (~$0.66/day)$0.66~$20

3. Amazon S3 (Simple Storage Service) Purpose:

  • Amazon S3 is used for storing static files, backend data, and media content such as images, videos, and documents for the application.

Cost:

StatusStorageDaily CostMonthly Cost
Free Tier5GB (free)$0.00$0.00
Beyond Free Tier5GB (~$0.03/day)$0.03~$1

4. Amazon CloudFront Purpose:

  • CloudFront is a Content Delivery Network (CDN) that distributes content from S3 and EC2.
  • It enhances access performance and reduces direct bandwidth usage from S3 and EC2.

Cost:

StatusBandwidthDaily CostMonthly Cost
Free Tier50GB free bandwidth$0.00$0.00
Beyond Free Tier50GB (~$0.10 - $0.16/day)$0.10 - $0.16~$3 - $5

5. Internet Gateway (IGW) Purpose:

  • The Internet Gateway connects the internal VPC network to the internet, enabling EC2 to send and receive data externally.
  • IGW is a critical component of AWS networking.

Cost:

  • Free of charge per AWS pricing.

6. IAM (Identity and Access Management) + VPC + Security Groups Purpose:

  • IAM is used to manage access control for users and groups, ensuring security.
  • VPC (Virtual Private Cloud) creates an isolated network environment for the system, ensuring security and resource management flexibility.
  • Security Groups act as a firewall, controlling network access to resources.

Cost:

  • Free of charge per AWS pricing.

7. Cost Summary

7.1. Cost Within Free Tier

ServiceTypeDaily CostMonthly Cost
Amazon EC2t2.micro$0.00$0.00
Amazon DocumentDBdb.t3.medium$0.00$0.00
Amazon S35GB storage$0.00$0.00
Amazon CloudFront50GB bandwidth$0.00$0.00
IAM + VPC + Security GroupsFree$0.00$0.00
Total$0.00$0.00

7.2. Cost Beyond Free Tier

ServiceTypeDaily CostMonthly Cost
Amazon EC2t2.micro~$0.30~$9
Amazon DocumentDBdb.t3.medium~$0.66~$20
Amazon S35GB storage~$0.03~$1
Amazon CloudFront50GB bandwidth~$0.10 - $0.16~$3 - $5
IAM + VPC + Security GroupsFree$0.00$0.00
Total~$1.10 - $1.15~$33 - $35

8. Conclusion

  • Within the Free Tier, the system operates at $0 cost.
  • Once the Free Tier expires, the maintenance cost will be approximately $33 - $35 per month.
  • If the system scales up, costs may increase, especially for DocumentDB, S3, and CloudFront usage.

Workshop Content

  1. Introduction
  2. Restricting Access with IAM Service
  3. Prepare VPC
  4. Create EC2 Instance
  5. Create S3
  6. Create AWS DocumentDB Service
  7. Deploying the Application to EC2
  8. Create CloudFront
  9. Cleaning Up Resources