AWS RDS
AWS RDS stands for Amazon Web Service Relational Database Service, running a DB instance in the cloud. Unlike its name, it also supports sequential databases such as MySQL.
Tutorial
Before beginning this, see the MySQL Tutorial.
Here you can both watch instructional video and follow very detailed a self-paced lab.
See the documentation below for snippets of tips.
Setting up AWS RDS
-
Log into AWS Management Console and Navigate to Services > RDS.
-
Click Launch a DB Instance.
-
Select MySQL, and click select.
-
You should be in Production?. Select the radio button next to MySQL under Dev/Test.
-
You should be in Specify DB Details. Select only show options that are eligible for RDS Free Tier.
-
For your DB Instance Class, select db.t2.micro.
-
Fill all the fields under Settings.
-
You should be in Configure Advanced Settings. For your VPC Security Group, default.
I don’t recall if I had a default group. If the option isn’t available, simply create a new security group.
-
Click Launch a new DB Instance.
-
Go to EC2 > Security Groups.
-
Select the security group you have specified and choose Actions > Edit Inbound Rules.
-
Set Source to Anywhere and click Save.
-
Wait until the DB Instance status is available in your RDS Dashboard > Instances.
-
Click on your instance to find your db endpoint (formatted as url:port);
Connecting to AWS RDS
-
Shell:
export AWS_HOST=YOUR_DB_ENDPOINT export AWS_USER=YOUR_DB_USER export AWS_PASSWORD=YOUR_PASSWORD export AWS_DATABASE=YOUR_DATABASE mysql -h ${AWS_HOST} -u{AWS_USER} -p{AWS_PASSWORD} {AWS_DATABASE}
-
Node.js:
-
To run locally, in your .env file, add:
HOST=YOUR_DB_ENDPOINT USER=YOUR_DB_USER PASSWORD=YOUR_PASSWORD DATABASE=YOUR_DATABASE
To configure heroku’s environment variables, run:
heroku config:set $(cat .env)
This is a shortcut for lazy people like me.
-
In your server.js:
var mysql = require('mysql'); var con = mysql.createConnection({ host : process.env.HOST, user : process.env.USER, password : process.env.PASSWORD, database = process.env.DATABASE }); con.connect(function(err){ if(err){ console.log('Error connecting to DB'); return; } console.log('Connection established'); });
-