I'm really struggling to configure my RDS instance to be accessible from my EC2 instance (created with Laravel Forge), as well as being able to access it locally from my SQL IDE.
I'd like the RDS instance to be in a private subnet (and eventually not be publicly accessible) as I only want it to be available to the EC2 instance, to my specific local IP address (for SQL IDE), and also to a Lambda function. But I don't know if I'm going about this all wrong. I've spent the better part of the morning messing around with this and I'm no further along than when I started.
Configuration:
- All resources are in a VPC that I created, and AWS created the associated public and private subnets and other resources as a part of the VPC creation wizard.
- RDS is publicly accessible
- RDS is on private subnets across 3 availability zones.
- I created the RDS instance using the wizard and chose the option to have it set up the security groups for EC2 access. So it created
rds-ec2-1with one inbound rule allowing MySQL/Aurora traffic on port 3306. with the source being the second security group,ec2-rds-1which has an outbound rule for MySQL/Aurora traffic on 3306. - I was reading that my private subnets need to have internet gateways, which I've attempted to configure. The route table for each subnet has the destination of
0.0.0.0/0and the target of my internet gateway. - I created an additional security group
rds-primary-sgthat I've been using to just tinker around and try to get some movement. I've added my local IP address with an inbound rule for MySQL/Aurora traffic, as well as one with my EC2 instance's private IP for MySQL/Aurora, for Custom TCP, and for SSH. (I'm clearly grasping at straws).
When I SSH into the EC2 instance and attempt to connect to mysql like so:
mysql -h my-instance.us-east-2.rds.amazonaws.com -u my-username -p my-password
I get ERROR 1045 (28000): Access denied for user
I've added an inbound rule to the rds-primary-sg group with my local IP address and with that I've tried to connect in my SQL IDE using the cluster endpoint and username/password, and I get the following:
Access denied for user db-username@my-local-ip (using password: YES)
I should mention the EC2 instance was created in Laravel Forge, using the existing VPC that I created in the AWS console.
Hoping someone has some experience with this type of configuration and can help me sort out what I'm doing wrong.
UPDATE
I went back and changed the password again based on a couple folks' comments was able to get connected!
What I will say is using the mysql command I referenced above with the -p flag, once it connected it seemed to want to use that value as the database I was trying to connect to, so it was trying to connect me to a database named the same as my password, and I got this error:
ERROR 1049: Unknown database 'my-password'
I ended up just doing this and it prompted me for the password and then successfully connected:
mysql -h my-instance.us-east-2.rds.amazonaws.com -u my-username -p