AWS RDS - Relational Database Service
Types of RDS Backup
- Automated Backups
- DB Snapshot
Creating a database
RDS → Create Database
- user:
admin
- password:
admin1234
- Endpoint (will be generated after db is created ): harshdeb1.ch8giy4subi2.ap-south-1.rds.amazonaws.com
Creating a Express app with Nodejs - API endpoint
const express = require("express");
let mysql = require("mysql");
let connection = mysql.createConnection({
host: "harshdeb1.ch8giy4subi2.ap-south-1.rds.amazonaws.com",
user: "admin",
password: "admin1234",
database: "testinitialdb",
});
connection.connect((err) => {
if (err) {
console.log("Error connecting to database", err);
} else {
console.log("Connected to database");
}
});
let app = express();
app.get("/api/users", (req, res) => {
let sqlQuery = "SELECT * FROM students";
connection.query(sqlQuery, (err, result) => {
if (err) {
console.log("Error executing query", err);
res.status(500).send("Error executing query");
} else {
res.send(result);
}
});
});
app.listen(3000, () => {
console.log("Server started on port 3000");
});
Create an Ubuntu Instance and install Nodejs in Ubuntu instance
https://www.knowledgehut.com/blog/web-development/install-nodejs-on-ubuntu
npm init -y
touch index.js
nano index.js
const express = require("express");
let mysql = require("mysql");
let connection = mysql.createConnection({
host: "harshdeb1.ch8giy4subi2.ap-south-1.rds.amazonaws.com",
user: "admin",
password: "admin1234",
database: "testinitialdb",
});
connection.connect((err) => {
if (err) {
console.log("Error connecting to database", err);
} else {
console.log("Connected to database");
}
});
let app = express();
app.get("/api/users", (req, res) => {
let sqlQuery = "SELECT * FROM students";
connection.query(sqlQuery, (err, result) => {
if (err) {
console.log("Error executing query", err);
res.status(500).send("Error executing query");
} else {
res.send(result);
}
});
});
app.listen(3000, () => {
console.log("Server started on port 3000");
});
cat index.js
npm install express mysql nodemon
node index.js
API Endpoint: http://13.201.120.15:3000/api/users