Configure Amazon RDS Proxy
Tags: aws, cloud, database, devops
Published: 2024-03-22 19:20:43

## Scenario

Amazon RDS Proxy can help busy online stores manage sudden traffic surges during sales events by pooling and sharing database connections. This ensures a smooth shopping experience even during peak times and helps the store recover quickly from any database failures, minimizing downtime and maintaining customer satisfaction.

This blog will cover everything we need to know about Amazon RDS Proxy and how to configure it!

- What is Amazon RDS?
- How does it work?
- Benefits of configuring Amazon RDS Proxy 
- Hands-on
- Conclusion

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oztfjuo3owj5iiq3ud8y.jpeg)

## What is Amazon RDS?

Amazon RDS stands for Amazon Relational Database Service. It is a web service that makes it easier to set up, operate, and scale a relational database in the cloud. Amazon RDS manages routine database tasks such as provisioning, patching, backup, recovery, and scaling, allowing developers to focus on their applications rather than the administrative aspects of managing a database.

## How does it work?

Amazon RDS Proxy simplifies connection management for Amazon RDS database instances by pooling and sharing database connections, actively handling network traffic between client applications and databases. It optimizes memory and CPU resources, reduces overhead on database servers, and improves application scalability and resilience to database failures

## Benefits of Configuring RDS Proxy?

1. Improved Database Connection Management
2. Enhanced Scalability
3. Better Fault Tolerance
4. Security
5. Database Caching

## Hands-on

**Amazon RDS Database**

Open the Amazon RDS service in the AWS console, choose Standard Database, and then pick the engine type that you want to use. Additionally, choose free-tier templates.

Enter your password in the settings section. Next, pick "Amazon VPC with No Public Access" under "Connectivity" and start a new security group. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ng7p5si9k6abjsq85txy.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rr2zjbj5k14occ7t8b1a.png)

finally, in additional configuration, provide a database name, make all the settings as default and create the database

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oi5kxr0lyzyn9ygfj2ey.png)

**AWS Secrets Manager**

Enter your credentials (password and username), choose the "Credentials for Amazon RDS database" secret type, and then pick the recently created database and encryption key.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qoruq2h4wkg8efhlytn.png)

Click Next after entering your name in the Configure Secret field. once more and developed the secret manager. Please copy the Secret ARN and keep it somewhere secure.

**AWS IAM Role and Policy**

Make a policy that permits the use of Amazon KMS and AWS Secret Manager. It should also be connected with an IAM role that permits the use of Amazon EC2 and RDS services. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ft8gkasytq1nhxntu7o.png)

Note that the policy is below. Setting up AWS KMS has an optional setting.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ct7tmq5uw5ylatw6gyqr.png)

`{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "GetSecretValue",
            "Action": [
                "secretsmanager:GetSecretValue"
            ],
            "Effect": "Allow",
            "Resource": [
                "AWS-Secret-Manager-ARN"
            ]
        },
        {
            "Sid": "DecryptSecretValue",
            "Action": [
                "kms:Decrypt"
            ],
            "Effect": "Allow",
            "Resource": [
                "AWS-KMS-ARN"
            ],
            "Condition": {
                "StringEquals": {
                    "kms:ViaService": "secretsmanager.ap-south-1.amazonaws.com"
                }
            }
        }
    ]
}`

**Amazon RDS Proxy**

Enter the proxy address and select Database in the target group configuration. Select the newly established Secret Manager role in Connectivty. Then, under Additional Configuration, build a new Security Group and select build Proxy.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x5noqefufxq3zeijj9mu.png)

**Amazon Security Groups**

Note: It is crucial that this step be configured correctly.

Allow inbound traffic from port 3306 for the rds proxy security group, which is for mysql/aurora, with the ec2 instance security group as the source.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i8xobjdw73go5lr2hs8o.png)

Allow incoming traffic from the rds proxy security group and the ec2 security group for the rds security group. The EC2 security group allows port 3306, which is used for MySQL and Aurora.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lm1irrsqd02k0zyz67cf.png)

Permit the post-22, or SSH, for the EC2 security group.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tb5rwltdx28ozs2tkheg.png)

**Amazon EC2 Instance**

Launch your EC2 instance, install MySQL and execute the command
mysql -h <proxy-endpoint> -P 3306 -u admin -p

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i195lf5a5td5tgbmoga6.png)

The connection to the Amazon RDS database is successful.

## Conclusion

Finally, we have completed a hands-on exercise to gain an understanding of the Amazon RDS proxy, including its importance and the reasons to use it.