RDS instance access from Ec2 instance from different region - amazon-web-services

I have following setup on AWS
One RDS instance in Region 1.
One Ec2 instance in Region 2.
EC2-Security Group sgrg2 in Region 2.
I am trying to access RDS from EC2 by adding Security Group to RDS instance list. It is not authorizing.
Moreover, while adding sgrg2 to RDS security group, it is saying ' EC2 security group sgrg2 for account xxx does not exist'.
Please help.

Communication between regions on AWS goes through the untrusted internet. You need to add the external IP of the EC2 instance to the security group of the RDS instance to get that to work. However, I would recommend you to move the EC2 instance into the RDS instance region, both for safety and cost. Safety as you need to expose your RDS instance to the internet (also make sure you use SSL connetions to the db). Cost as Amazon charges for traffic across regions as regular in/out traffic.

The following link helped me connect to RDS from an EC2 instance in a different region
https://forums.aws.amazon.com/thread.jspa?threadID=102827
The trick was to use http://baremetal.com/cgi-bin/dnsip to confirm which IP number RDS security group would accept, thereby giving access to my EC2 instance.
This said it does make a lot of sense to keep both RDS & EC2 instances in the same region, when feasible/practical.

Related

How to connect my AppRunner instance to RDS?

I've configured RDS with the suggested defaults and no public access.
Then I put my AppRunner instance in the same security group as RDS by creating a VPC connector. I can see the same VPC and subnets listed on both sides yet I somehow don't have a connection to RDS still (my AppRunner instance can't connect). What am I doing wrong? Isn't it enough to put them in the same security group and VPC?

Connection from Lambda to RDS in a different account

I have an RDS in one AWS Account - say Acct-1.
The RDS is public (i know it's not a good idea and there are other solutions for that)
I have a lambda in another AWS Account - say Acct-2 which runs in a VPC.
I have setup VPC peering between the 2 accounts, the route table entries are in place as well as the security groups IN/OUT bound policies in place.
In Acct-2 I can verify that I can connect to the RDS instance in Acct-1 using a mysql cient from an EC2 instance. The EC2 instance is in the same subnet as the Lambda and they both have the same security group.
But the Lambda gets a timeout connection. The Lambda has the typical Lambda execution role that Allows logs, and network interfaces.
Thoughts on what could be missing ? Does the RDS need to grant specific access to the Lambda service even if it's running in a VPC ?
Clarification: There is no route to the RDS instance from the internet. Clearly, the ec2 host is able to resolve the Private IP for the RDS instance from the DNS name and connect.
Lambda is unable to resolve the private IP for the RDS instance.
I'm trying to keep the traffic within AWS so as to not pay egress costs.

How can I connect to Amazon RDS instance from Amazon EC2 instance

I have set an Amazon EC2 instance and an Amazon RDS instance. These two instances are both available.
I tried to connect to the RDS instance from my localhost, and I succeeded:
(I'm sorry about the picture's content is in Chinese, but the content in the red border means "success".)
In a word, when I used my localhost, I can connect to the RDS instance that I just set successfully.
But when I tried to use the EC2 instance to connect the same RDS instance with oracle sqldeveloper, I CANNOT EVEN CONNECT TO IT.
The error message is:
The Network Adapter could not establish the connection
How can I solve this issue?
Update:
My Security Group is:
The security groups match the AWS EC2 instance`s PRIVATE IP.
This answer is not necessarily a fix for your situation, but rather a recommendation about how to configure a security group.
Rather than using IP addresses within a security group, it is better to refer to another security group.
The configuration would be:
EC2-SG security group: Attach this to your EC2 instance. Allow access on desired ports (eg port 80).
RDS-SG security group: Attach this to your RDS instance. Allow access from EC2-SG- on desired port (eg port 3306).
This way, the RDS-SG will permit access from any EC2 instance associated with the EC2-SG security group. This will continue to work even if IP addresses change or additional EC2 instances are launched with the same EC2-SG.

How to connect to a RDS instance in a different AWS region

I have an EC2 instance in one region, N.California. I have an RDS instance in EU/Ireland. I am not able to connect to the RDS instance from the EC2 instance, the connection times out. This tutorial by aws says that I would need to use the Public IP of the RDS instance in order to connect to it. But this public IP is not available on the AWS console, I'm not even sure if we're supposed to be using any other than RDS endpoints. We're also disallowed from adding a security group from one region to the security group of another.
I am really unsure about how to proceed.
I am answering my own question because my own solution worked, and it might be of use to someone else considering that the AWS tutorial is wrong.
To connect, add a custom tcp rule over port 3306 in the security group Ingress Rules for the RDS instance, with the EIP of your EC2 instance as the allowed host. Voila.

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.