DVA-C03 practice question: Concurrency and performance tuning (3 of 3)
Troubleshooting and Optimization A free question from our original DVA-C03 practice exam. Try it, then open the answer to see why each option is right or wrong.
A Lambda function is invoked about 500 times a minute.
Each invocation creates a new AWS SDK client and a new database connection inside the handler. CloudWatch shows that most of the warm-invocation duration is spent creating them. Database connections must stay within the database's limit, and no user data may be kept between invocations.
What should the developer change?
Choose one answer.
AA. Create the SDK client and database connection outside the handler, so warm invocations reuse them.
BB. Store the connection object in an environment variable so that later invocations can read it.
CC. Raise the function's reserved concurrency, so that more execution environments are created.
DD. Move the setup code into a Lambda layer, so that it runs before the handler starts.
B. Wrong: Environment variables hold strings, not live connection objects. They are also set from configuration, not created during a run.
C. Wrong: More execution environments means more open connections to the database, which works against its connection limit. It does not remove the setup cost either.
D. Wrong: A layer packages files and libraries. It does not run setup code before the handler, so the connections would still be created on each invocation.
Explanation
Lambda reuses an execution environment between invocations, so initializing SDK clients and database connections outside the handler lets warm invocations skip that work. The same reuse is why per-user data must not be stored in module-level state.
Want more on Concurrency and performance tuning? The 5 full-length practice sets have 13 more Concurrency and performance tuning questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets →