Lesson 6 of 7 Amazon RDS and Aurora

Pooling Database Connections with RDS Proxy

This lesson explains how RDS Proxy, a managed connection pool, protects RDS and Aurora databases from connection storms and makes failover faster.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe what RDS Proxy does.
  • Explain how applications connect through the proxy endpoint.

What RDS Proxy does

Relational databases allow a limited number of connections, and each connection consumes memory. Applications that open many short-lived connections, such as Lambda functions, can exhaust that limit. RDS Proxy sits between applications and the database, pooling and reusing connections so that many clients share a small number of database connections.

During a failover, the proxy holds client connections open and redirects them to the new primary, which cuts failover time for applications by up to 66%. It can enforce IAM authentication for clients, while the database credentials are held in AWS Secrets Manager, so applications store no passwords. The proxy is highly available across Availability Zones and is reachable only from within the VPC.

The following diagram shows many functions sharing a small pool of connections.

RDS Proxy pooling connections. Many Lambda functions open short-lived connections to the proxy, which shares a small pool of database connections among them. Clients can authenticate with IAM while the database credentials stay in Secrets Manager, and during a failover the proxy keeps client connections open and redirects them to the new primary.
The proxy is reachable only from within the VPC, so the functions must be attached to it.
Select all that apply

What RDS Proxy gives

Exam skills 3.3.2 · 2.1.5

Identify what RDS Proxy provides.

Log in to try this activity Interactive activities are free with an account.

Using it

Applications use RDS Proxy by connecting to the proxy's endpoint instead of the database endpoint, with no other code changes. Read-only proxy endpoints route connections to read replicas, so reads can also benefit from pooling.

RDS Proxy is charged per vCPU of the underlying database instance, or per Aurora capacity unit for Aurora Serverless. It supports the MySQL, PostgreSQL, MariaDB and SQL Server engines on both Amazon RDS and Aurora.

Worked example

Lambda exhausting database connections

A serverless API on Lambda writes to Aurora PostgreSQL. During a sale, 800 concurrent functions each open a connection, and the database rejects new connections.

FixEffect
Put RDS Proxy between Lambda and AuroraHundreds of function connections share a small pool of database connections
Authenticate to the proxy with IAMNo database password in the functions
Open the connection outside the handlerEach environment reuses its connection

During an Aurora failover, the proxy also keeps the functions' connections open and redirects them to the new writer, so the API sees a short pause rather than errors.

Check yourself

How does RDS Proxy shorten failover for applications?

Show answer

Applications stay connected to the proxy, which redirects to the new primary, so they do not have to wait for DNS changes.

Exam Tips

Remember for the exam

  • When Lambda overwhelms the database with connections, use RDS Proxy.
  • To reduce application downtime during RDS failover, use RDS Proxy.
  • To make applications authenticate with IAM rather than database passwords, use RDS Proxy with IAM authentication.