Creating RDS proxy
Proxy requests to AWS RDS
Connect your RDS Database to Elastic Load Balancers using proxy requests. You can connect by:
- Registering an Instance to the Load Balancer
- registering an IP Address.
Creating an RDS proxy service (for RDS MySQL and postgres databases)
AWS does not support load balancing an RDS through their regular Network Load Balancer, and you cannot use the IP address you fetch from your RDS Endpoint, because it may change without warning.
Creating the RDS proxy
You can create the RDS Proxy and use it on your Load Balancer.
Procedure
- Navigate to your RDS Console.
- Select Proxies in the navigation menu.
- Click on Create proxy.
- Go to Connectivity section, and click the Create a new secret.
- Enter your RDS login credentials.
- After creating the new secret in the Secret Manager, return to the RDS Proxy creation page and refresh it.
- Enter a valid name for your proxy.
- Select the relevant settings (your DB Engine, encryption, etc.).
- Select the new secret you just created under Connectivity.
- Choose the Subnets where you want the proxy to reside. Check the I acknowledge this limited service agreement for the RDS Proxy.
- Click on Create proxy.
Get the proxy's IP addresses. **This is usually not recommended, but as stated before, according to AWS, these IP addresses should stay the same.
To get the IP address:
-
Connect to a machine that runs in the same VPC as your RDS Proxy.
-
Make sure this machine has permission to connect to the service.
-
Run this command:
dig +short YOUR_RDS_PROXY_DNS_ENDPOINT -
Output displays one or more IP addresses
-
Take the IPs this command prints out.
-
Create a target group that routes traffic to IP addresses, and set them to register as the targets of this group.
-
Connect your Target Group to a Load Balancer using a Listener.
Creating an EC2 proxy machine (for other DB engines and on-prem databases)
You can create an EC2 machine within your VPC (where your RDS Database resides). Make sure it has access to connect to your RDS in the relevant port.
After creating this machine, you can install a ProxySQL, and configure it using the configuration files (all the information is available on ProxySQL's Official Tutorial).
You can easily register this EC2 instance to a "Target Group" (using the relevant port) and connect the "Target Group" to your load balancer.