Course menuDVA-C02

Exams / DVA-C02 / Concurrency and performance tuning / Question 3

DVA-C02 practice question: Concurrency and performance tuning (3 of 3)

Troubleshooting and Optimization A free question from our original DVA-C02 practice exam. Try it, then open the answer to see why each option is right or wrong.

A Lambda function creates a new database connection and a new AWS SDK client inside its handler on every invocation. Profiling shows that most of the time on warm invocations is spent setting these up. What should the developer change to reduce warm invocation duration?

Choose one answer.

  1. A. Create the SDK client and connection outside the handler so they are reused.
  2. B. Store the connection object in an environment variable between invocations.
  3. C. Increase the function's reserved concurrency so more environments are created.
  4. D. Move the setup code into a Lambda layer so that it runs before the handler.
Show the answer and explanation

Answer: A

  • A. Right: Correct. Code outside the handler runs once per execution environment, and later invocations in that environment reuse the objects.
  • B. Wrong: Environment variables hold strings set in configuration. They cannot hold live objects such as connections.
  • C. Wrong: More environments mean more cold starts and more setup, not less work per invocation.
  • D. Wrong: Layers package code and libraries. Where the setup code is called still decides how often it runs.

Explanation

Lambda reuses an execution environment for later invocations. Initialising SDK clients and database connections outside the handler lets warm invocations reuse them, cutting duration and cost. AWS also advises against keeping user-specific data in that reused state.

Study

Keep practising

Answer questions with a score at the end, or practise just this topic with the explanation after each one. No sign-up needed.