DVA-C02 Development with AWS Services Practice Question
A developer is writing a Lambda function that needs to access an Amazon RDS MySQL database. The function will be invoked frequently. What is the BEST practice for managing the database connection?
⚠ Common exam trap
Candidates often choose Option C because they remember the general Lambda rule of 'reusing connections outside the handler.' However, for relational databases (RDS), this approach still leads to connection exhaustion when Lambda scales. RDS Proxy (Option D) is the correct AWS-recommended architectural pattern for this scenario.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Use Amazon RDS Proxy to manage the connection pool.
For Lambda functions accessing relational databases like Amazon RDS, the best practice is to use Amazon RDS Proxy. Because Lambda functions can scale rapidly to hundreds or thousands of concurrent executions, they can quickly exhaust the database's connection pool. RDS Proxy pools and shares these connections, improving scalability and application resilience. While opening connections outside the handler (Option C) is a good general practice, it does not solve the connection exhaustion problem under high concurrency and frequent invocations.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Close the database connection at the end of each invocation.
Why it's wrong here
Closing the database connection at the end of each Lambda invocation prevents the execution environment from reusing an established connection for subsequent invocations. This forces the Lambda function to re-establish a new TCP connection, perform authentication, and potentially re-negotiate SSL/TLS for every single request. This constant connection setup and teardown introduces significant latency and unnecessary overhead, diminishing performance and increasing resource consumption for both the Lambda function and the database.
- ✗
Open a new database connection inside the handler for each invocation.
Why it's wrong here
Opening a new database connection inside the handler for every invocation is highly inefficient due to the inherent overhead of establishing a new connection. Each connection requires a handshake, authentication, and resource allocation, which adds significant latency to every request. Furthermore, repeatedly opening new connections can quickly exhaust the maximum connection limits of the underlying database, leading to connection failures and service disruptions under moderate to high load.
- ✗
Open the database connection outside the handler function and reuse it.
Why it's wrong here
Opening the database connection outside the handler function allows the Lambda execution environment to reuse this established connection across multiple subsequent invocations of the same function instance. During a "warm start," the initialized connection remains active, eliminating the overhead of connection setup for each request. This significantly reduces latency, improves overall performance, and minimizes the load on the database by maintaining fewer, longer-lived connections, making it the most efficient approach for database interactions in Lambda.
- ✓
Use Amazon RDS Proxy to manage the connection pool.
Why this is correct
While Amazon RDS Proxy is an excellent service for managing database connection pooling, multiplexing, and resilience for serverless applications, it is not the most direct or fundamental solution for how a developer should structure their Lambda function's code for efficient connection handling. RDS Proxy operates as an intermediary layer, abstracting connection management from the Lambda function itself. The question specifically asks about the developer's approach within the function, and reusing connections within the execution context is a more direct and immediate code-level optimization.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
Go deeper
Related to this question
About these practice questions
Courseiva writes every DVA-C02 question from scratch — 1,135 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.