Courseiva
Question 1,316 of 724
Development with AWS ServiceseasyMultiple ChoiceObjective-mapped

DVA-C02 Development with AWS Services Practice Question

A developer is using AWS Lambda to process messages from an Amazon SQS queue. The function needs to access an Amazon DynamoDB table. What is the MOST secure way to grant the Lambda function access to DynamoDB?

⚠ Common exam trap

Candidates often think storing credentials as environment variables is acceptable for simplicity, but the exam emphasizes that IAM roles with least-privilege policies are the most secure and AWS-recommended approach for granting permissions to AWS services like Lambda.

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

Assign an IAM role to the Lambda function with a policy that grants the required DynamoDB permissions.

AWS Lambda uses an IAM execution role to securely obtain temporary credentials via the AWS Security Token Service (STS). By attaching a policy that grants only the required DynamoDB actions (e.g., GetItem, PutItem) on specific tables, you follow the principle of least privilege. This avoids hardcoding long-term credentials and eliminates the risk of credential exposure.

Answer analysis

Option-by-option breakdown

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

  • Use the Lambda function's execution role to grant full administrative access to DynamoDB.

    Why it's wrong here

    Granting full administrative access to DynamoDB via the Lambda function's execution role is a severe security misconfiguration. This approach violates the principle of least privilege, as the function would possess permissions far beyond what is necessary to process messages, creating a significant attack surface. If the Lambda function were compromised, an attacker could potentially gain control over all DynamoDB tables in the account, leading to data exfiltration or destruction.

  • Store the AWS access key and secret access key as environment variables in the Lambda function.

    Why it's wrong here

    Storing AWS access keys and secret access keys directly in Lambda environment variables is highly insecure and strongly discouraged. These static credentials could be inadvertently exposed through logs, code repositories, or if the Lambda function's configuration is accessed. This practice bypasses AWS's secure credential management mechanisms and creates a hardcoded dependency, making credential rotation difficult and increasing the risk of unauthorized access to AWS resources.

  • Assign an IAM role to the Lambda function with a policy that grants the required DynamoDB permissions.

    Why this is correct

    Assigning an IAM role to the Lambda function with a precisely scoped policy is the secure and recommended method for granting AWS service permissions. This approach leverages temporary credentials automatically managed by AWS, eliminating the need to store static access keys. The IAM policy can be crafted to adhere strictly to the principle of least privilege, allowing the function only the specific DynamoDB actions (e.g., dynamodb:PutItem, dynamodb:GetItem) on designated resources it requires to perform its task.

  • Create an IAM user with DynamoDB access and use its credentials in the Lambda function.

    Why it's wrong here

    Creating an IAM user and embedding its long-lived credentials within a Lambda function is an anti-pattern for service-to-service communication. IAM users are primarily designed for human interaction or programmatic access from external applications where roles are not feasible. Using an IAM user for a Lambda function introduces static, long-lived credentials that must be securely stored and rotated manually, which is less secure and more operationally complex than leveraging temporary credentials provided by an IAM role.

Quick reference

Cloud Service Model Comparison

ModelYou ManageProvider ManagesExamples
IaaSOS, runtime, apps, dataHardware, hypervisor, networkingEC2, Azure VMs, GCP Compute Engine
PaaSApps and dataOS, runtime, middleware, hardwareElastic Beanstalk, Azure App Service
SaaSData and settings onlyEverything elseMicrosoft 365, Salesforce, Workday
FaaS / ServerlessFunction code onlyInfra, scaling, runtimeLambda, Azure Functions, Cloud Run
CaaSContainers and appsKubernetes, OS, hardwareEKS, AKS, GKE

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.