DEV Community

Cover image for Deploy My First Node.js App on AWS: EC2 + Docker + RDS MySQL Explained
Soumen Bhunia
Soumen Bhunia

Posted on • Edited on

Deploy My First Node.js App on AWS: EC2 + Docker + RDS MySQL Explained

Hi everyone,
My name is Soumen Bhunia. This is my first blog. In this blog, I build and deploy my first Node.js app using Docker, hosted on an AWS EC2 instance, and connected to a MySQL database hosted via Amazon RDS

Technologies Used

Step-by-Step Setup Guide

Step 1: Create an RDS MySQL Instance

  1. Go to Amazon RDS Console.
  2. Click Create Database.
  3. Choose:
    • Engine type: MySQL
    • Use case: Free Tier
  4. Under Settings:
    • Set a DB instance identifier
    • Master username: admin
    • Master password: Set a secure password (avoid special characters like @, %, etc.)
  5. In Connectivity:
    • Enable Public access = Yes (for development purposes)
    • Create a new VPC security group
    • Add an inbound rule to allow MySQL/Aurora (port 3306) from Anywhere (0.0.0.0/0)

After RDS is created, copy the endpoint/hostname — you'll use it to connect your app to the database.

Step 2: Launch and Configure an EC2 Instance

  1. Go to Amazon EC2 Console.

  2. Launch a new instance:

    • Amazon Linux 2 AMI (Free Tier eligible)
    • Choose t2.micro (Free Tier)
  3. In Security Group, allow:

    • HTTP (port 80) – for web traffic
    • SSH (port 22) – for connecting to the instance
    • Optional: Restrict access by IP for SSH

Step 3: Install Docker on EC2

Once connected to EC2, run the following:

sudo yum update -y
sudo yum install -y docker
sudo service docker start
sudo usermod -aG docker ec2-user
Enter fullscreen mode Exit fullscreen mode

Important: Log out and log back in to activate Docker permissions for ec2-user.

Step 4: Run the Dockerized Node.js App

Pull the Docker image:

sudo docker pull philippaul/node-mysql-app:02
Enter fullscreen mode Exit fullscreen mode

Then run your container, replacing the values with your actual RDS credentials:

docker run --rm -p 80:3000 \
-e DB_HOST="your-db-endpoint.rds.amazonaws.com" \
-e DB_USER="admin" \
-e DB_PASSWORD="your-db-password" \
-d philippaul/node-mysql-app:02
Enter fullscreen mode Exit fullscreen mode

Your app should now be accessible at your EC2 public IP on port 80.

Web interface screenshot

web interface image

Optional: Test the MySQL Connection

You can test connecting to the database from inside EC2 using a MySQL Docker client:

docker run -it --rm mysql:8.0 mysql \
-h your-db-endpoint.rds.amazonaws.com \
-u admin -p
Enter fullscreen mode Exit fullscreen mode

Enter your password when prompted. If you connect successfully — your EC2 can talk to your RDS instance.

Thanks for Reading!

Hope this gives you some perspective.

Coming Up Next:

More hands-on cloud projects and DevOps tips — stay tuned!

Let’s Connect:

Share your thoughts in the comments or reach out on LinkedIn.Your feedback means a lot!

Top comments (0)