Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy Django using MySQL to AWS EC2 and RDS

I'm trying out AWS EC2 and RDS. I had followed this tutorial and it worked, but the tutorial is missing a database migration. https://www.youtube.com/watch?v=YJoOnKiSYws So, could someone point me in the right direction to continue with the database migration?

I've tried https://support.cloud.engineyard.com/entries/21009887-Access-Your-Database-Remotely-Through-an-SSH-Tunnel but it didn't work for me because of an RDS permission issue.

I've also tried the instructions on Amazon, http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html but it just confused me even more.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Importing.NonRDSRepl.html

I've posted a message on AWS forum, but no one answered. And I was hoping that someone here can help me out. I just need some plain simple example such as

step1.  From local pc export MySQL with mysqldump (done)
step2.  Upload local mysqldump.sql file to EC2  (I don't know how to do)
step3.  import mysqldump.sql on EC2 to RDS (I don't know how to do)
step4.  connect django web app to use new MySQL database that has data dump  (don't know how)

I really appreciate your help.

BTW, the data is in MySQL on my local computer running maverick OS (I hope that info is helpful).

like image 425
vt2424253 Avatar asked Mar 24 '14 00:03

vt2424253


People also ask

Can you run RDS on EC2?

To connect to a private RDS DB instance from a local machine using an EC2 instance as a jump server, follow these steps: Launch and configure your EC2 instance and configure the network setting of the instance. Configure the RDS DB instance's security groups. Connect to the RDS DB instance from your local machine.


1 Answers

If you are using RDS you don't have SSH access so creating an SSH tunnel is not an option.

So what's missing from your question is whether you are in a VPC or not, so assuming you are not in a VPC. In essence:

  1. On the RDS security group, open the ingress EC2 security group that your EC2 instance you are going use to access the database with is in. For example, on the RDS console this shows up as the actual EC2 security group name

    EC2 RDS security group

(To get to Security groups click RDS->Security Groups->Create DB Security Group, you first new to create an DB Security Group to see the screenshot above or you can use the default DB Security Group):

  1. Dump your database on the server that you are running your original MySQL database. Hopefully this is the same server that is in the EC2 security group that you are allowing as an ingress on your RDS security group above: mysqldump -uroot -p <database-name> > database-name.sql

  2. Load the database from the EC2 instance in EC2 security group allowed by RDS security group:

    • mysql -uroot -h<RDS-hostname> -p < database-name.sql

    • The RDS hostname is something like this: database-name.xxxxxxxxxx.us-east-1.rds.amazonaws.com

  3. You don't have to connect to the RDS database to load a dump into it. But if you want to connect to it you can just run: mysql -uroot -p -h<RDS-hostname>

In case you you are in a VPC make sure that the EC2 instance that you are running the commands from is in the same VPC and subnet as your RDS instance. You have to create a VPC Subnet group for your VPC on the RDS console, this Subnet group has to be in two different Availability Zones if you are running a multi-az RDS instance. Other than that the procedure is the same.

like image 55
Rico Avatar answered Sep 30 '22 16:09

Rico