Cannot access Amazon RDS instance - amazon-web-services

I have created a free-tier PostgreSQL RDS instance and everything appears to looks good on the portal. However, I am unable to get to the instance.
Going through the troubleshooting steps, they mention it could a firewall issue on my end. However, a quick ping from an external site reveals the same timeout issue.
Is there a step that I've missed?

Ping is typically disabled in AWS Security Groups. It is not recommended as a method of checking network connections.
The best method would be to use an SQL client to connect to the database via JDBC or ODBC.
Things to check:
Your RDS instance was launched as Publicly Accessible
Your RDS instance was launched in a Public Subnet (Definition: The subnet's Route Table points to an Internet Gateway)
The Security Group permits connections on the database port (this is also where you could permit PING access, but no guarantee that it would work with an RDS instance)

Check the associated Security Groups that you have tagged. Security groups hold the firewall rules. Either you may have to tweak the group that you have selected or try changing / modifying the group that you (or your profile) have access to.

Related

Alternative to AWS's Security groups in GCP?

Is there an alternative to AWS's security groups in the Google Cloud Platform?
Following is the situation which I have:
A Basic Node.js server running in Cloud Run as a docker image.
A Postgres SQL database at GCP.
A Redis instance at GCP.
What I want to do is make a 'security group' sort of so that my Postgres SQL DB and Redis instance can only be accessed from my Node.js server and nowhere else. I don't want them to be publically accessible via an IP.
What we do in AWS is, that only services part of a security group can access each other.
I'm not very sure but I guess in GCP I need to make use of Firewall rules (not sure at all).
If I'm correct could someone please guide me as to how to go about this? And if I'm wrong could someone suggest the correct method?
GCP has firewall rules for its VPC that work similar to AWS Security Groups. More details can be found here. You can place your PostgreSQL database, Redis instance and Node.js server inside GCP VPC.
Make Node.js server available to the public via DNS.
Set default-allow-internal rule, so that only the services present in VPC can access each other (halting public access of DB and Redis)
As an alternative approach, you may also keep all three servers public and only allow Node.js IP address to access DB and Redis servers, but the above solution is recommended.
Security groups inside AWS are instance-attached firewall-like components. So for example, you can have a SG on an instance level, similar to configuring IP-tables on regular Linux.
On the other hand, Google Firewall rules are more on a Network level. I guess, for the level of "granularity", I'd say that Security Groups can be replaced to instance-level granularity, so then your alternatives are to use one of the following:
firewalld
nftables
iptables
The thing is that in AWS you can also attach security groups to subnets. So SG's when attached to subnets, are also kind of similar to google firewalls, still, security groups provide a bit more granularity since you can have different security groups per subnet, while in GCP you need to have a firewall per Network. At this level, protection should come from firewalls in subnets.
Thanks #amsh for the solution to the problem. But there were a few more things that were required to be done so I guess it'll be better if I list them out here if anyone needs in the future:
Create a VPC network and add a subnet for a particular region (Eg: us-central1).
Create a VPC connector from the Serverless VPC Access section for the created VPC network in the same region.
In Cloud Run add the created VPC connector in the Connection section.
Create the PostgreSQL and Redis instance in the same region as that of the created VPC network.
In the Private IP section of these instances, select the created VPC network. This will create a Private IP for the respective instances in the region of the created VPC network.
Use this Private IP in the Node.js server to connect to the instance and it'll be good to go.
Common Problems you might face:
Error while creating the VPC Connector: Ensure the IP range of the VPC connector and the VPC network do not overlap.
Different regions: Ensure all instances are in the same region of the VPC network, else they won't connect via the Private IP.
Avoid changing the firewall rules: The firewall rules must not be changed unless you need them to perform differently than they normally do.
Instances in different regions: If the instances are spread across different regions, use VPC network peering to establish a connection between them.

moving from publicly accessible rds database to using bastion ec2 instance to connect to it

If one has a publicly accessible rds database on aws, and wants to instead use a bastion ec2 instance to access and perform database functions (anyone on the internet should be able to use the app and perform database functions in accordance with the features provided by the app), how should one go about performing this shift? I have tried searching the internet but often I get loads of information with terminology that isn't entirely easy to digest. Any assistance would be greatly appreciated.
Again, I want the general public to be able to use and access the app's provided db functions, but not have them be able to access the database directly.
A typical 3-tier architecture is:
A Load Balancer across public subnets, which sends traffic to...
Multiple Amazon EC2 instances in private subnets, preferable provisioned through Amazon EC2 Auto Scaling, which can scale based on demand and can also replace failed instances, which are all talking to...
A Database in a private subnet, preferably in Multi-AZ mode, which means that a failure in the database or in an Availability Zone will not lose any data
However, your application may not require this much infrastructure. For low-usage applications, you could just use:
An Amazon EC2 instance as your application server running in a public subnet
An Amazon RDS database in a private subnet, with a security group configured to permit access from the Amazon EC2 instance
Users would connect to your application server. The application server would connect to the database. Users would have no direct access to the database.
However, YOU might require access to the database for administration and testing purposes. Since the database is in a private subnet, it is not reachable from the Internet. To provide you with access, you could launch another Amazon EC2 instance in a public subnet, with a security group configured to permit you to access the instance. This instance "sticks out" on the Internet, and is thus called a Bastion server (named after the part of a castle wall that sticks out to allow archers to fire on invaders climbing the caste wall).
You can use port forwarding to connect to the Bastion server and then through to the database. For example:
ssh -i key.pem ec2-user#BASTION-IP -L 3306:DATABASE-DNS-NAME:3306
This configures the SSH connection to forward localhost:3306 to port 3306 on the named database server. This allows your local machine to talk to the database via the Bastion server.
You will need to create private subnets for this and update DBsubnet groups accordingly with private subnets only. Moreover in DB security group add bastion and app instances security group as source for db port.
Like if you're using mysql engine, allow 3306 for target instances secuirty group id's.

Security Groups for AWS DMS

I am trying to setup DMS between my on-prem db and cloud. When I try to setup the cloud instance doesn't seem to have necessary privileges to connect to on-prem db. Should I add the security groups in AWS to DMS Replication Instance or Target Database?
This maybe of use to you, it is not directly an answer but it will help you to diagnose it.
You need a security group on both the replication instance and the target database.
You will need to have your replication instance in a security group that can reach both the source and target.
I would start by confirming that your replication instance can reach the on premise source. Fire up a small ec2 instance in the same security group as you replication instance and confirm you can ping and telnet to the on prem source. Make sure you use telnet on the correct port, a failure is ok so long as it doesn't hang. If it hangs you have a firewall or security group issue. Following the ping and telnet tests I would check the flowlogs and confirm you have Accepted traffic going both ways on the correct port.
If this is a success you should be able to create a source endpoint to your on premise Database. Any issue your at this point again check your Flowlogs. After that make sure your on premise DB will accept remote connections and the user you are connecting with has authority to do so.
The target database security group will need to allow in traffic from your replication instance on the correct port. I'm not sure if the ping test will work but the telnet should. Again look for traffic in your flow logs you want accepts in both directions.

Setting RDS to 'publicly available' to 'YES'

I just finished setting up an RDS instance but I couldn't connect to it using sql workbench.
What I did was I set 'publicly available' to 'YES' and I was able to connect to it.
I'm new to this and would appreciate some guidance with regards to the actions that I did.
Are there any risk of having it available to public? currently, I only have my IP as the only allowed traffic.
Allowing your RDS instance to be publicly accessible by only your own IP is fine.
If you only need part time access to your server, I would add and remove my IP address from the security group as needed. I use hand written batch scripts to do this.
If your RDS instance does not need real public access except for SQL WorkBench, then I would setup OpenVPN, keep RDS private and do all my work over a VPN. OpenVPN makes all of this very easy. Automatically routes my traffic destined for my VPC over the VPN using private IP addresses.
With this week's announcemnt of inter-region VPC peering, there is even less need for making non-web servers public.
Announcing Support for Inter-Region VPC Peering

Writing to an RDS MySQL database from an EC2 instance

I have a t2.micro instance running, that is producing some data that needs to be written to a database. So, I created a RDS database with MySQL on it.
The issue I'm facing is, nonsurprisingly, getting the EC2 instance to communicate with the RDS database in any way/shape/form.
I'm been battling with it all day. I'm left with these bits of confusion:
I figured I've just add the public IP of the EC2 instance to the security group of the RDS. Turns out the RDS doesn't really have a security group, only a VPN. So how do I allow communication from the EC2 instance, then?
Speaking of security groups, do I need to se the EC2 up to require outbound connections?
The RDS has an 'endpoint' and not a public IP as far as I can tell. So I can't add it to any security group at all. Is this correct?
Am I going to have to figure out how to use Elastic Beanstalk or some other way to get these components to play together?
These are all the things I'm trying to troubleshoot but I'm not getting anywhere. There doesn't seem to be any good blogs / etc; mostly what I'm finding is stuff on how to get the RDS to be accessed by your local hardware, not an EC2 instance.
How should I set this up?
There are two ways to allow inbound connection to RDS database: CIDR/IP or EC2 security group.
You can go to VPC, at the left panel there is "Security Groups" (yes, RDS do have security group). Click that, and choose your DB security group (if you already have the RDS instance created) or create a new one.
Under connection type, choose either CIDR/IP or EC2 security group.
If you choose to go with CIDR/IP, you should know what IP address your EC2 instance is and put the address or range in e.g. "10.11.12.0/24".
If you choose to go with EC2 security group, you should know the security group nameof your EC2 instance and select it from the dropdown provided e.g. "my security group".
Please note that the EC2 instance and the RDS instance need to be able to "see" each other i.e. in the same region, VPC, subnets with proper NACL (network access control list) etc.
Speaking of outbound connection and security group, no, security groups only manage inbound connection.
Hope that helps, let me know if I can make my answer clearer.