AWS can't access RDS (Postgres) from network - postgresql

I created a Postgres DB on RDS from my home in country X, currently I am in Y and I can not access the DB. I get a connection timed out response. The DB is set to be publicly accessible. I guess it has something to do with subnets / ACL or something similar. Since I am new to AWS I would love to get help for a quick fix. I need the DB to evaluate a project, later on I plan to dive deeper into AWS.
Thanks for your help.

If you have not modified the default ACL then that should not be the problem.
Since it worked when you were at home, I believe your already have the correct route set in your VPC route table (0.0.0.0/0 to internet gateway).
I would start pinging the RDS connection endpoint to make sure you are able to resolve the hostname and there is no typo (I made this mistake before).
My first guess is that the issue lies in the RDS instance security group inbound setting. You need to make sure you are allowing port 5432 (Postgres default port) connection from either 0.0.0.0/0 (Anywhere in the world) or your location Y IP address (Checkout whatismyip.com if you are unsure).
If you have a multi-az deployment, another unlikely scenarios might be that the RDS instance in subnet A failed over to the secondary RDS instance in subnet B, which has a different subnet / route table setting.

Related

Unable to connect the server, Timeout Expire to Postgres RDS

I've had a postgres RDS launched on AWS
I have public access enabled
I also check the security group, inbound rules
Things look okay to me, but the issue here is that I cannot connect to the server, I got "unable to connect to the server, timeout expired" with the pgAmin4, using correct endpoint and port
Trying to debug, I realize when I deploy the postgres on a server (might be a VM), I have to modify the configuration file (pg_hba.conf), so I guess I have to do the same with RDS. Is that true with RDS?
I got the default option group named default:postgres-13, but I cannot modify the option.
Please help for clue.
Edited: correct a typo
I realize that exposing a RDS to public network never be a good practice. Keep it in a private subnet and use a bastion host inside the VPC to access the database instance.
And, ssh tunneling through the bastion host is considered as a good choice for access from public network.

how to connect to physical mongo database(i.e. Non-Cloud mongo db server) using AWSlambda function

while connecting physical mongo DB from AWS lambda function getting an error like "MongoServerSelectionError: getaddrinfo ENOTFOUND ". Could you pls guide me how to connect mongo DB using AWS lambda function. Thanks very much.
A little more information about your setup would be useful:
Does the MongoDB server live within your AWS VPC or On-Premises?
If it resides in AWS, is your Lambda function also part of that VPC?
Is DNS Resolution enabled in the VPC?
Did you check that the right Security Groups are attached?
Is the DNS-Name of your MongoDB publicly resolvable (or privately if the Lambda function sits inside the VPC)? - try nslookup my-mongo-server.com
Not having that information I can hazard a guess:
You probably want to connect to an On-Premises (i.e. not in AWS) instance of MongoDB which sits in a private Network in some Data Center.
You've been given a DNS-Name like db.mycompany.internal and are trying to connect to that. The problem is, that this DNS-Name is not publicly resolvable, i.e. the public DNS system doesn't know about your domain.
Your code is trying to get the IP address of your database server to connect to, but can't do that.

connect to amazon RDS on scaleway server

I wanna try amazon RDS for my project, so I created micro instance in amazon AWS. I am new to AWS, I added my server IP to security group and VPC. I tried to connect from server:
psql -h digrin.asdada.us-west-2.rds.amazonaws.com -p 5432 -d digrin -U my_username -W
psql: could not connect to server: Connection timed out
Is the server running on host "digrin.asdada.us-west-2.rds.amazonaws.com" (54.71.212.12) and accepting
TCP/IP connections on port 5432?
I can login from localhost, so I was going through amazon AWS settings multiple times and added IP of server everywhere I thought might be causing problems. No luck.
Then I tried to login from another server, which IP I did not add anywhere to AWS and I did connect successfully - so my database is pulicly available.
So I thought my server provider is blocking 5432 port or something such. I created ticket with them (Scaleway) and this is what I got:
Hello,
Please understand that we do not provide support regarding software management / Firewall configuration.
On our end, nothing is locked network-wise on any port unless you modify your security group's configuration.
I don't understand where the issue could be. Any ideas?
Network access to your RDS instances is controlled by a security group which acts somewhat like a firewall. Rules can be crafted in security groups to allow other members of that security group to connect to each other, which is the default policy in the default security group. Thus because your RDS instance and your EC2 instance are members of the same security group they can communicate freely but nothing else outside of that group can communicate with either host.
An instance can be a member of more than one security group at a time and if there are rules allowing the traffic in any of the security groups for which the instance is a member then the traffic will be allowed. In the spirit of security I would suggest not opening more ports than necessary and would not recommend opening ports within the default security group as that would effectively make those ports accessible on all instances in that security group.
So, to allow access to your Scaleway host:
Create a new security group from the VPC console, add a rule to this group that allows the MySQL port to be accessed from the IP address of your Scaleway host (or from anywhere, depending on your level of security concerns)
Attach that security group to your database in addition to the default security group through the RDS console

I set my RDS (psql) db to NOT publicly accessible and now I cannot connect to my db using pgAdmin. How can I connect to it now?

I am using elastic beanstalk and I have my REST application running there. This REST API application can access my RDS postgres database, and my RDS is only accessible in my VPC. I have updated my VPC settings, so my REST API does seem to work, since I have some endpoints I'm hitting to insert, and I can also make requests to pull the most recent data, etc.
However... I can't tell for sure!
I was using PgAdmin to connect to my database, but since changing the RDS instance's publicly accessible setting to NO, I can no longer connect to it from my macbook. Is there a way I can still connect to that database using PgAdmin or psql, perhaps by using SSH or something?
From my reading it seems I cannot SSH to RDS directly, so I am not sure how to proceed. Thank you!
Choosing the option YES for publicly accessible for your DB instance will give your instance a public IP address.
Is your RDS in private subnets ?
If yes, I've had that issue before. What I did in my case was to setup an openVPN server and have the client on my mac. But that solution was driven by having not only RDS in the private subnets but other services so we could access them through the VPN connection.
As for OpenVPN, I have made a blog post for it: here
From your question as much I can understand you need to access your DB from public outside amazon VPC
just modify the DB instance
open rds dashboard select your DB instance you want to modify
top instance action >> Modify >> change the Publicly available option to yes.
image reference:
change your Db security group port to anywhere or your Ip.(so at least you can only access)
Now you can access your DB from your MacBook

Cannot access google cloud SQL from google container engine

I'm still having problems accessing the cloud SQL instance from a GCE container. When I try to open up mysql, I get the following error:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial
communication packet', system error: 0
The connection works fine from my local machine, though (The instance has a public IP and I have added my office's IP to the 'allowed Networks'). So, the instance is accessible through the internet just fine.
I guess the db's access control is blocking my access from the gce network, but I'm unable to figure out how to configure this.
I added my project to "Authorized App Engine Applications" in the Cloud SQL control panel, but that doesn't seem to help.
EDIT:
If I add "0.0.0.0/0" to Allowed Networks, all works well. This is obviously not what I want, so what do I need to enter instead?
EDIT2: I could also add all public IPs from my kubernetes cluster (obtained through gcloud compute instances list) and add them to the cloud sql access list manually. But, this doesn't seem to be right, does it?
The recommended solution is to use SSL connection with that 0.0.0.0/0 CIDR. This is to limit the connection to the correct key. I also read that they won't promise you a specific IP range so the CIDR /14 might not work some times. I had to do the SSL connection with my Cloud SQL for the same reasons.
You should use the public IP addresses of the GCE instances to correctly allow traffic to your Cloud SQL instance (as you mentioned in EDIT2).
You can find more information in Cloud SQL documentation: https://cloud.google.com/sql/docs/gce-access
If you add the /14 CIDR block for your Container Engine cluster as the source address range does that work?
To find the CIDR block for your cluster, click on the cluster name in the Google Cloud Console and find the row labeled "Container address range".