DEV Community

Cover image for 🧩From Code to Cloud: My First AWS Full-Stack Deployment (EC2 + S3 + RDS)
AKASH S
AKASH S

Posted on • Edited on

🧩From Code to Cloud: My First AWS Full-Stack Deployment (EC2 + S3 + RDS)

🧠 Overview

  • ⚙️ EC2 – to host my Python (Flask) backend
  • 🎨 S3 – to serve my React (or HTML/JS) frontend as a static website
  • 🗄️ RDS (MySQL) – as a managed cloud database

Project Structure:

Task-Manager-RDS/
├── backend/
│   ├── app.py
│   ├── schema.sql
│   └── requirements.txt
└── frontend/
    └── index.html (or React build)
Enter fullscreen mode Exit fullscreen mode

Use this repo if needed

🛠️ 1. Setting Up the Backend on EC2

Step 1: Launch an EC2 Instance

  • OS: Ubuntu 24.04 LTS
  • Instance Type: t2.micro (Free Tier)
  • Enable HTTP, HTTPS, and SSH in the Security Group
  • Generate and download a .pem key pair

Image description

Step 2: Connect via SSH

  • ssh -i key.pem ubuntu@<your-ec2-public-ip>
  • Refer my blogs to connect EC2 with SSH if needed.

Step 3: Setup Python Environment and Clone Our Repo

  • Setting up Venv:
sudo apt update
sudo apt install python3-pip python3-venv
python3 -m venv taskman
source taskman/bin/activate

Enter fullscreen mode Exit fullscreen mode
  • Clone Repo:
git clone https://github.com/<your-username>/Task-Manager-RDS.git
cd Task-Manager-RDS/backend
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Image description

Step 4: Start the Flask Server

  • python3 app.py
  • Now the backend is running on http://<EC2-IP>:5000

Image description

☁️ 2. Deploying MySQL with Amazon RDS

Step 1: Create an RDS MySQL DB

  • Engine: MySQL
  • Public Access: Yes (for now, for testing)
  • Security Group: Add EC2 instance's IP for port 3306

Image description

Step 2: Connect to RDS from EC2

  • mysql -h <rds-endpoint> -u <username> -p

Step 3: Create DB & Table

CREATE DATABASE IF NOT EXISTS taskmandb;
USE taskmandb;
CREATE TABLE IF NOT EXISTS tasks (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(255) NOT NULL,
  status VARCHAR(20) DEFAULT 'pending',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Enter fullscreen mode Exit fullscreen mode
  • Now, our backend-EC2 connects directly to the RDS DB.

Image description

🌐 3. Hosting Frontend on S3

Step 1: Create S3 Bucket

  • Name: taskman-frontend-ak
  • Region: us-east-1
  • Enable: Static website hosting
  • Index Document: index.html

Step 2: Upload Frontend Files

aws s3 sync ./frontend s3://taskman-frontend-ak
Enter fullscreen mode Exit fullscreen mode

or upload via Console.

Image description

Step 3: Make S3 Bucket Public

  • Uncheck Block All Public Access
  • Add this Bucket Policy:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::taskman-frontend-ak/*"
    }
  ]
}

Enter fullscreen mode Exit fullscreen mode

Step 4: Access the Site

Image description

Check the images weather all are working in correct manner:

  • Database Table Verification:

Image description

  • POST and GET and health Check of Backend:

Image description

Main Things to be changed after creating the resources:

  • RDS - credentials in app.py
  • EC2 Public ip in script.js
  • Schema should be created in an organized manner.

Tips to avoid Charges:

  • Delete the resources atonce our work is done.
  • Focus more on main services like EC2 , VPC and S3.
  • Set up a billing alert and budget planing in billing and Cost dashboard.

📣Stay tuned for more Blogs and deployments.

Top comments (1)

Collapse
 
santhoshnc profile image
Santhosh NC

@akashabish , the full stack deployment blog is insightful

Some comments may only be visible to logged-in visitors. Sign in to view all comments.