Monica Heddneck
Monica Heddneck

Reputation: 3135

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:

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?

Upvotes: 0

Views: 542

Answers (1)

Tony Prawiro
Tony Prawiro

Reputation: 61

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.

Upvotes: 1

Related Questions