Courseiva
Development with AWS ServiceseasyMultiple ChoiceObjective-mapped

DVA-C02 Development with AWS Services Practice Question

A developer is building a serverless application using AWS Lambda and Amazon DynamoDB. The Lambda function needs to read and write items to a DynamoDB table. What is the BEST way to securely provide the Lambda function with the necessary AWS credentials?

⚠ Common exam trap

Watch out — candidates often think environment variables (Option A) are a secure storage mechanism because they are not in the code, but they fail to recognize that long-term access keys are still exposed and violate the IAM roles best practice for serverless applications.

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 an IAM role with DynamoDB permissions and attach it to the Lambda function.

The best practice for granting AWS Lambda functions access to DynamoDB is to create an IAM role with the necessary DynamoDB permissions (e.g., dynamodb:GetItem, dynamodb:PutItem) and attach that role to the Lambda function. This follows the principle of least privilege and leverages AWS Identity and Access Management (IAM) roles, which provide temporary, automatically rotated credentials via the AWS Security Token Service (STS). This approach eliminates the need to manage long-term access keys and ensures secure, auditable access.

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 AWS access key and secret key in the Lambda environment variables.

    Why it's wrong here

    Storing static AWS access keys and secret keys directly in Lambda environment variables is a significant security risk. These credentials are not automatically rotated and are visible in plain text to anyone with console access or sufficient IAM permissions to view the Lambda function's configuration. This practice violates the principle of least privilege and exposes long-lived credentials, making the application vulnerable to compromise if the Lambda function or its configuration is ever accessed maliciously.

  • Create an IAM role with DynamoDB permissions and attach it to the Lambda function.

    Why this is correct

    Creating an IAM role with specific DynamoDB permissions and attaching it to the Lambda function is the AWS-recommended and most secure approach. When the Lambda function executes, it automatically assumes this IAM role, which provides temporary, short-lived credentials to interact with DynamoDB. This method adheres to the principle of least privilege by granting only necessary permissions and eliminates the need to manage static credentials within the function code or configuration, significantly enhancing security.

  • Create an IAM user with programmatic access and store the credentials in the Lambda code.

    Why it's wrong here

    Creating an IAM user with programmatic access and embedding its static credentials directly within the Lambda function's code is a severe security anti-pattern. Hardcoding credentials makes them difficult to rotate, prone to accidental exposure through version control systems, and provides long-lived access that could be exploited indefinitely if compromised. This approach completely bypasses AWS's secure identity and access management mechanisms designed for compute services.

  • Use the Lambda function's default full admin access provided by AWS.

    Why it's wrong here

    AWS Lambda functions do not inherently possess any default full administrative access; they operate with an execution role that must be explicitly defined and assigned. Without an attached IAM role, a Lambda function would lack the necessary permissions to interact with other AWS services like DynamoDB, resulting in authorization failures. This option is fundamentally incorrect as it misrepresents how permissions are managed for serverless compute.

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

One of 724 original DVA-C02 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.