Courseiva
Development with AWS ServicesmediumMultiple ChoiceObjective-mapped

DVA-C02 Development with AWS Services Practice Question

A developer is writing a Lambda function that processes events from an Amazon S3 bucket. The function needs to access a DynamoDB table to store metadata about the S3 objects. Which of the following is the MOST efficient way to initialize the DynamoDB client in the Lambda function?

⚠ Common exam trap

A common mix-up: candidates think creating the client inside the handler is safer for avoiding stale connections, but AWS Lambda's execution environment reuse makes global initialization both safe and more efficient.

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

Create the DynamoDB client outside the Lambda handler function, in the global scope.

Initializing the DynamoDB client outside the Lambda handler (in global scope) allows the client to be reused across multiple invocations within the same execution environment. This avoids the overhead of creating a new client on every invocation, which reduces latency and conserves resources. AWS Lambda reuses the global scope for subsequent invocations after the first, making this the most efficient approach.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Store the DynamoDB table name as a global variable and create the client inside the handler.

    Why it's wrong here

    Storing the DynamoDB table name as a global variable is an acceptable practice for configuration, as it's a static value that doesn't change per invocation. However, creating the DynamoDB client *inside* the handler function means that a new client object is instantiated and initialized with every Lambda invocation. This repeatedly incurs the overhead of client setup, connection pooling, and resource allocation, negating the performance benefits of reusing an execution environment.

  • Use a static variable inside the handler to cache the DynamoDB client.

    Why it's wrong here

    Declaring a static variable *inside* the handler for a DynamoDB client is less efficient than initialising it in the global scope. While static variables generally persist their value across function calls within a single process, in the context of a Lambda handler, placing the client outside the handler function ensures it is initialised only once per execution environment lifecycle, not per invocation. This option is tempting because using static variables for caching is a common optimisation pattern to avoid repeated expensive object creation, and it correctly aims to reuse the client across invocations when the execution environment remains warm.

  • Create the DynamoDB client inside the Lambda handler function every invocation.

    Why it's wrong here

    Creating the DynamoDB client inside the Lambda handler function for every invocation is the least efficient approach. Each time the function is invoked, the AWS SDK must initialize a new client, establish connections, and allocate associated resources. This process adds significant latency to every request, increases CPU utilization, and can lead to higher costs due to longer execution times, especially for frequently invoked functions.

  • Create the DynamoDB client outside the Lambda handler function, in the global scope.

    Why this is correct

    Creating the DynamoDB client outside the Lambda handler function, in the global scope, is the recommended best practice for optimizing Lambda performance. This ensures the client is initialized only once when the Lambda execution environment is first created during a cold start. For subsequent 'warm' invocations within the same execution environment, the pre-initialized client is reused, significantly reducing latency by avoiding repeated client setup overhead and connection establishment.

Quick reference

AWS S3 Storage Class Comparison

Storage ClassMin DurationRetrievalUse Case
S3 StandardNoneImmediateFrequently accessed data
S3 Standard-IA30 daysImmediateInfrequent access, rapid retrieval
S3 One Zone-IA30 daysImmediateNon-critical infrequent data
S3 Intelligent-TieringNoneImmediate–hoursUnknown or changing access patterns
S3 Glacier Instant90 daysMillisecondsArchive with instant retrieval
S3 Glacier Flexible90 daysMinutes–hoursArchive, flexible retrieval
S3 Glacier Deep Archive180 daysHoursLong-term compliance archive

About these practice questions

Courseiva writes every DVA-C02 question from scratch — 724 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 →

How Courseiva writes practice questions · Editorial policy

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.