DVA-C02 Security Practice Question
A company is using AWS Lambda to process sensitive data. The Lambda function needs to access an S3 bucket in the same account. What is the BEST practice for granting permissions?
⚠ Common exam trap
DVA-C02 often tests the misconception that embedding access keys in environment variables is acceptable for Lambda, when the correct answer is always an IAM execution role with temporary credentials.
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 a policy granting S3 access and attach it to the Lambda function.
The AWS best practice for granting a Lambda function access to other AWS services is to create an IAM role with the required permissions and assign it as the function's execution role. Lambda assumes this role at runtime and the function receives temporary credentials via the environment, so no long-lived secrets are needed. This follows least-privilege and avoids credential management overhead.
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 an S3 bucket policy that allows access from the Lambda function's ARN.
Why it's wrong here
Using an S3 bucket policy for same-account access is not the best practice because permissions for a Lambda function to access resources within the same AWS account should primarily be defined on the Lambda function's IAM execution role. This centralises the function's access controls on its identity. Bucket policies are powerful for granting access directly to the resource, making them suitable for cross-account access scenarios where a principal from another account needs permission to interact with the bucket, or for public access.
- ✓
Create an IAM role with a policy granting S3 access and attach it to the Lambda function.
Why this is correct
This is the AWS best practice for granting permissions to Lambda functions. By assigning an IAM execution role, the Lambda function automatically assumes this role and receives temporary, frequently rotated credentials from the AWS Security Token Service (STS) to interact with S3. This approach adheres to the principle of least privilege, centralizes access control, and eliminates the need to manage long-term static credentials within the function code or configuration, significantly enhancing security.
- ✗
Generate a key pair and use it to authenticate the Lambda function to S3.
Why it's wrong here
AWS key pairs are specifically designed for secure SSH access to EC2 instances, enabling users to prove their identity when connecting to a virtual server. They are not a mechanism for programmatic authentication between AWS services like Lambda and S3. Lambda functions authenticate using IAM roles, which provide temporary credentials, making key pairs entirely irrelevant and inappropriate for this inter-service communication scenario.
- ✗
Store the AWS access key ID and secret access key in the Lambda environment variables.
Why it's wrong here
Storing static AWS access key IDs and secret access keys directly in Lambda environment variables is a severe security anti-pattern. These long-term credentials are difficult to rotate, can be accidentally exposed through logs or configuration exports, and violate the principle of least privilege if not meticulously managed. This method bypasses the secure, temporary credential management provided by IAM roles, creating a significant attack vector.
Quick reference
AWS S3 Storage Class Comparison
| Storage Class | Min Duration | Retrieval | Use Case |
|---|---|---|---|
| S3 Standard | None | Immediate | Frequently accessed data |
| S3 Standard-IA | 30 days | Immediate | Infrequent access, rapid retrieval |
| S3 One Zone-IA | 30 days | Immediate | Non-critical infrequent data |
| S3 Intelligent-Tiering | None | Immediate–hours | Unknown or changing access patterns |
| S3 Glacier Instant | 90 days | Milliseconds | Archive with instant retrieval |
| S3 Glacier Flexible | 90 days | Minutes–hours | Archive, flexible retrieval |
| S3 Glacier Deep Archive | 180 days | Hours | Long-term compliance archive |
Go deeper
Related to this question
About these practice questions
This DVA-C02 question is part of Courseiva's 1,135-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Amazon Web Services exam blueprint
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.