DVA-C02 Security Practice Question
A developer needs to grant a Lambda function read-only access to an S3 bucket. Which IAM entity should be used to attach the permissions?
⚠ Common exam trap
Test-takers frequently confuse resource-based policies (which grant access to the principal specified in the policy) with identity-based policies (which grant permissions to the principal the policy is attached to), and incorrectly think a bucket policy alone can grant permissions to a Lambda function without an execution role.
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 the necessary permissions and assign it to the Lambda function as the execution role.
Lambda functions require an IAM role (execution role) to obtain temporary AWS credentials via the AWS Security Token Service (STS). This role must have a trust policy allowing Lambda to assume it, and an attached permissions policy granting read-only access to the S3 bucket. This is the standard and secure method for granting permissions to an AWS service like Lambda.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Create an IAM user and provide the credentials to the Lambda function.
Why it's wrong here
Creating an IAM user and embedding its long-term credentials directly within a Lambda function is a significant security anti-pattern. AWS Lambda functions are designed to leverage IAM roles, which provide temporary, automatically rotated credentials through the AWS Security Token Service (STS). Storing static IAM user access keys and secret keys in code or environment variables introduces a high risk of credential compromise and violates the principle of least privilege by not using temporary, scoped permissions.
- ✗
Attach a resource-based policy to the S3 bucket.
Why it's wrong here
While resource-based policies on an S3 bucket can grant permissions, they define *who can access the resource* rather than *what the Lambda function itself is allowed to do*. For a Lambda function to perform actions, it needs an associated execution role with an identity-based policy that grants it permissions to *make requests* to services like S3. A resource policy alone would not provide the Lambda function with the necessary permissions to initiate API calls; it only dictates if a *specific principal* (which would still be the Lambda's execution role) is allowed access once it makes a request.
- ✗
Attach a policy to an IAM group and add the Lambda function to the group.
Why it's wrong here
IAM groups are specifically designed to manage permissions for collections of *IAM users*, simplifying the assignment of common policies. Lambda functions, however, are compute resources that assume an IAM *role* for their execution permissions and are not considered IAM principals that can be added as members to an IAM group. This approach fundamentally misapplies the purpose of IAM groups, which are not intended for service principals like Lambda functions.
- ✓
Create an IAM role with the necessary permissions and assign it to the Lambda function as the execution role.
Why this is correct
This is the correct and AWS-recommended approach for granting permissions to a Lambda function. An IAM role, configured with a trust policy allowing `lambda.amazonaws.com` to assume it, serves as the function's execution role. An attached identity-based permissions policy then explicitly defines the specific actions the Lambda function is authorized to perform, such as `s3:GetObject` for read-only access, ensuring adherence to the principle of least privilege and providing temporary credentials.
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
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 →
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.