How to Deploy Your Node.JS Server Using MySQL Database on AWS (Mac)

I. Set up Security Groups

  • Type: Custom TCP, Protocol: TCP, Port Range: 3000, Source: Anywhere
  • Type: Custom TCP, Protocol: TCP, Port Range: 3000, Source: Load Balancer Security Group ID
  • Type: Custom TCP, Protocol: TCP, Port Range: 3000, Source: My IP
  • Type: SSH, Protocol: TCP, Port Range: 22, Source: My IP
  • Type: MYSQL/Aurora, Protocol: TCP, Port Range: 3306, Source: My IP
  • Type: MYSQL/Aurora, Protocol: TCP, Port Range: 3306, Source: Web Tier Security Group ID

II. Set up an app server in the web tier

  1. Create an EC2 instance and bootstrap it
  • Install Node.js and MySQL server on the EC2 instance
  • clone the code for my server
  • install all the node dependencies
  • start the server app.js
yum update -y
curl --silent --location | sudo bash -
sudo yum -y install nodejs mysql-server git -y
  • name: AppServer
  • project: p3
  • env: test/prod
cd Documents/S3/EDISS/PROJ
ssh -i "./Tina-EDISS.pem" ec2-user@[public DNS/public IP]
git clone
npm install
node app
scp -i /Users/Tina/Documents/S3/EDISS/PROJ_local/Tina-EDISS.pem /Users/Tina/Documents/S3/EDISS/PROJ/test/ ec2-user@

III. Create more servers in the web tier using an AMI

1. Create an AMI of the current instance

2. Create multiple instances with the AMI

3. Launch the Server in all the instances

npm install
node app

IV. Set up an Classic Load Balancer

1. Create a Load Balancer

  • Classic Load Balancer →
  • Listeners: HTTP port 3000, Availability Zones: at least chose 2 →
  • Security Groups: Group for Load Balancer →
  • Ping Port: 3000, Ping Path: /health, Response Timeout:4, Interval: 5 →
  • Add EC2 Instances later
  • Routing: Create a new target group →
  • Register instances to the target group
  1. it sends requests from the same client to the same server the whole time so when the instance got killed, all following requests from its clients will still be routed to it and fail. And,
  2. it will cause unbalance load among instances as the load balancer balances requests based on the traffic but not server load. So it could happen that one server gets a lot of big requests.

2. Set up the ping target response in your code

app.get('/health', function(req, res){
res.send({"message": "Instance is alive"});
}); // just return anythin with 200

3. Check if Load Balancer is attached to all instances

V. Set up an Auto Scaling Group (ASG)

1. Create a Launch Configuration

  • Create from existing AMI
  • User Data
  • Use app server security group

2. Create a Scaling Group

  • Add subnets →
  • Use scaling policies to adjust the capacity of this group: choose “Scale the Auto Scaling group using step or simple scaling policies”, Add new alarm for both the increase group size and decrease group size section.

3. Using Application Load Balancer with Auto Scaling Group

V(1) Setup MySQL Database using the RDS service

1. Setup a MySQL Database Instance

  • MySQL →
  • Dev/Test (Production version has 2 database instances in 2 different availability zones with one being primary and one being the backup, and synchronization is handled by Amazon) →
  • DB Instance Class chose db.t2.micro — 1 vCPU, 1 GiB RAM,
  • Multi-AZ Deployment: No,
  • DB Instance Identifier: EDISS-P3,
  • Master Username: admin,
  • Master Password: adminadmin →
  • Availability Zone: Make sure same as your primary instances to decrease latency
  • VPC Security Groups: DB tier

2. Connect App Servers to the DB

V(2) Or, Hold MySQL Server on Ec2

1. Install MySQL

2. Start mysql

3. Enable chkconfig on MySQL

4. Launch the mysql shell and enter it as the root user:

5. Launch MySQL

6. Create database, table and insert default users in the table

7. Exit mysql from the terminal

8. Or stop mysql when you need to

VI. System Functionality Tests

VI. System Availability Tests

VII. System Performance Tests

  • Install Elasticsearch
  • Start the service
  • Set Elasticsearch to be accessible from the network




she/her/她 linkedIn @tinabu insta @_tinahbu

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Sine and Cosine Angles Sum and Difference Identities

Top 10 Extensions for Web Developers

Thumbnail for Article: Top Extensions for Web Developers.


Noteworthy VS Code Extensions

All you need to know about Route in Laravel 5

Quick Stfalcon Insight on The Messenger Component (Symfony)

What’s in a List Comprehension? — Part 2

Select the Right CMS in 6 Easy Steps

CMS Recommendation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tina Bu

Tina Bu

she/her/她 linkedIn @tinabu insta @_tinahbu

More from Medium

Deploy React app on Cloud Front

Amazon Transcribe Serverless Java: Speech To Text

AWS HTTP API directly to SQS with User Agent and IP Address

Using EC2 to create a microservice