DVA-C02 Question 195
Single answerYou are developing a serverless application using AWS Lambda and Amazon S3. Your Lambda function processes images uploaded to an S3 bucket and stores metadata in an Amazon DynamoDB table. The S3 bucket and DynamoDB table are in the same AWS account. However, after deploying the application, you notice that the Lambda function fails with an 'AccessDeniedException' when trying to access the S3 bucket. What is the MOST likely cause of the issue?
- A
The Lambda function's execution role does not have the necessary permissions to access the S3 bucket.
- B
The S3 bucket's bucket policy does not allow access from the Lambda function.
- C
Amazon S3 and Lambda are in different AWS Regions, causing a region mismatch.
- D
The Lambda function's code is missing the logic to parse the images from the S3 bucket.
Show answer and explanation
Correct answer: A
Explanation
When a Lambda function interacts with other AWS services, such as S3, it requires an IAM execution role with appropriate permissions. In this scenario, the 'AccessDeniedException' indicates that the Lambda function's execution role lacks the necessary permissions to access the S3 bucket. To resolve this, you need to attach a policy to the role that allows 's3:GetObject' or other relevant permissions for the S3 bucket.
- A. Correct.
This is the correct answer. Lambda requires an IAM execution role with appropriate permissions to access other AWS services, such as S3. If the role does not have the necessary permissions, the function will fail with an 'AccessDeniedException'.
- B. Incorrect.
While S3 bucket policies can restrict or allow access, they are not required if the Lambda function's execution role already has sufficient permissions to access the bucket. In this case, the issue is likely with the Lambda execution role itself.
- C. Incorrect.
Amazon S3 and Lambda can operate across regions, but this would not cause an 'AccessDeniedException'. The error indicates a permissions issue, not a region mismatch.
- D. Incorrect.
This is unrelated to the error. The 'AccessDeniedException' indicates a permissions issue, not a problem with the Lambda function's code or logic.