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).
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:
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
(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):
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
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
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.
Related
Yesterday AWS launched Aurora serverless for PostgreSQL, but it doesn't seem to have the same configuration options as other RDS databases, I can't set it to public facing for example, it forces me to have a VPC.
Now, I have no clue how to apply these VPC things to PgAdmin, I've tried setting the inbound for the security group to all ports and ips but it still won't connect (no server response).
How can I connect to a RDS Database inside a VPC using PgAdmin?
Opening the security group didn't work.
I realize this question is old, but I kept coming back to it as I worked this out.
This solution is similar to #genkilabs solution but simpler.
Steps:
Spin up an ec2 micro instance in the same vpc as the database. You will tunnel through this.
Add the security group for your ec2 to the inbound rules of the database's security group.
ssh into the ec2 instance and install psql (and postgress...) with:
sudo amazon-linux-extras install postgresql10
Verify that you can connect to your database with psql:
psql -h {server} -p 5432 -U {database username} -d {database name} -p
In PGAdmin create a new server connection
Enter the database host, username, and password as usual.
Go to the SSH Tunnel tab
turn on ssh tunneling
enter your ec2 hostname for the tunnel host
enter your ssh username
select the identity file and find the .pem or .cer file for your ec2 instance.
Save and done. You should now be able to connect to the serverless Aurora database from your local PGAdmin.
If you have trouble connecting to the database form the ec2, this guide may be helpful. The same steps apply connecting from ec2 as from cloud9.
EDIT Sept '22: With Serverless V2 you can now select "public access" during the initial create, and connect directly (provided your VPC and security groups allow it). However, it is still recommended for production / "enterprise" use to still connect only though a "bastion" or "jump-box".
Officially, you can't...
Per the docs:
You can't give an Aurora Serverless DB cluster a public IP address. You can access an Aurora Serverless DB cluster only from within a virtual private cloud (VPC) based on the Amazon VPC service.
However, connecting to a serverless DB from a non-Amazon product is just officially discouraged, it is not impossible.
The best solution I have found so far is to create an autoscaling cluster of bastion boxes within the same VPC. Then use them to tunnel through. The great part about this strategy is that it exposes a standard postgre format URL, so it can be used with pgAdmin, Navicat, ActiveRecord or any other ORM that uses typical connection urls.
...The bad part is that (so far) it seems to enforce a 30 sec timeout on connections. So you better get all your transactions wrapped up quick like.
If anyone can do better, I'd love to hear how as well.
I have an application running in EC2 and a PostgreSQL db running in RDS, both inside the same VPC. I believe I have created the necessary security group, but how do I determine the hostname of the db server to use from my application?
Expand the row for that instance in the RDS dashboard. Then you can see the DNS name to use next to "Endpoint:".
My RDS instance in the image above has the domain: [redacted].us-west-2.rds.amazonaws.com. Hovering over the information icon (i on a dark circle) next to it shows me the security groups that can access it.
In trying to move a website to operate via Elastic Beanstalk (ELB), I chose the t2 series of EC2 instances, and in doing so, was forced to create a Virtual Private Cloud (VPC). This site connects to a MySQL database via RDS, and I'm not having any luck getting the ELB site to access the database.
I've tried reviewing this:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.RDS.html?icmpid=docs_elasticbeanstalk_console
The above link starts by saying "works great for development and testing environments, but is not ideal for a production environment", which confuses me as it doesn't say what would be better in its place - I need a database connected to the site!
It has all sorts of information and I tried several of the things it suggested regarding connecting to an existing database (not creating a new one). It mentions on step 6 of the "To modify the ingress rules on your RDS instance's security group" section to access the ingress tab, which doesn't exist for me.
I've tried editing the security group associated with the database via the RDS dashboard under "security groups", but it does not list the security groups that are associated with the VPC or the EC2 instance launched by ELB. I tried pushing the IP addresses, elastic IPs, and still can't get the site to see the database.
I'm at a loss. Can anyone explain how to connect an ELB distributed EC2 instance with an RDS database through the VPC required by t2 instances?
The statement that "This works great for development and testing environments, but is not ideal for a production environment" is just referring to having ElasticBeanstalk create the RDS instance for you. This can be done by configuring the "Database" section when creating a new EB environment.
The downside of letting EB create the RDS instance for you is that your web instance and database instance will be strongly connected, and if you ever terminate your web instance, your database will also be terminated, including all of your snapshots.
However, I think you're taking the "external" part of "external database" too literally. Your RDS instance should definitely be within the same VPC as your web instance. However, you should create it and connect your web instance to it manually. Connecting to the database involves setting five environment variables (listed below) and configuring the security group to allow connections from the web instance to the database.
The environment variables you'll need to set on your web instance are as follows:
RDS_HOSTNAME=instancename.region.rds.amazonaws.com
RDS_DB_NAME=databasename
RDS_PASSWORD=databasepassword
RDS_USERNAME=databaseuser
RDS_PORT=5432
When you set up a new Elastic Beanstalk cluster you can access your EC2 instance by doing this:
eb ssh
However, it's not clear how to access the RDS instance.
How do you access an RDS in an Elastic Beanstalk context in order to perform CRUD operations?
The RDS command-line can be accessed from anywhere, by adjusting the RDS security group.
Check your AWS VPC configuration.
The security-group will need to be
adjusted to allow you to connect from a new source/port.
Find the security Group-id for the RDS.
Find that group in AWS Console > VPC > secuirty groups
Adjust the Inbound and Outbound Rules accordingly.
You need to allow access to/from the IP or security group that needs to connect to the RDS.
FROM: https://stackoverflow.com/a/37200075/1589379
After that, all that remains is configuring whatever local DB tool you would like to use to operate on the database.
EDIT:
Of additional note, if the ElasticBeanstalk Environment is configured to use RDS, the EC2 Instances will have environment variables set with the information needed to connect to the RDS.
This means that you can import those variables into any code that needs access.
Custom environment variables may also be set in Elastic Beanstalk Environment Configuration, and these too may be included this way.
PHP
define('RDS_HOSTNAME', getenv('RDS_HOSTNAME'));
$db = new rds(RDS_HOSTNAME);
Linux CommandLine
mysql --host=$RDS_HOSTNAME --port=$RDS_PORT -u $RDS_USERNAME -p$RDS_PASSWORD
RDS is a managed database service, which means it is that you can only access it through database calls.
If it is a MySQL database you can access through your EC2 instance through mysql like this:
mysql -u user -p password -h rds.instance.endpoint.region.rds.amazonaws.com
or set it up to work with your app with settings needed for that.
Make sure that you set up security groups correctly so that your EC2/other service has access to your RDS instance.
Update:
If you want what you are asking for then you should use an EC2 instance with a mysql server on. It would cost the same (even though a fraction of performance is lost in comparison). An EC2 instance you can turn off when you are not using as well.
I have done everything correctly till the 4th step as mentioned on this page.
http://docs.amazonwebservices.com/AmazonRDS/latest/GettingStartedGuide/ConnectToDBInstance.html
But I can not telnet nor ping to the Endpoint server mentioned. What else should I check if I want to connect to this mysql server from another AWS EC2 instance?
I guess you haven't setup RDS security group properly. Add the security group of the ec2 from which you want to access RDS, to the RDS security group for that RDS.
By default RDS security group blocks all connections.