DVA-C02 Question 348
Single answerYou are developing a serverless application using AWS Lambda and the AWS SDK for Python (boto3). During execution, your function makes a call to get an object from an S3 bucket. However, the function occasionally fails with an error. Upon investigation, you notice the error message: 'botocore.exceptions.ClientError: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.' What could be the most likely cause of this error?
- A
The S3 bucket does not exist.
- B
The IAM role attached to the Lambda function does not have sufficient permissions to access the S3 bucket.
- C
The object key specified in the GetObject request does not exist in the S3 bucket.
- D
The Lambda function exceeded its timeout limit while making the GetObject API call.
Show answer and explanation
Correct answer: C
Explanation
The 'NoSuchKey' error occurs when the specified object key does not exist in the S3 bucket. In this case, the Lambda function is attempting to retrieve an object using a key that either was not uploaded or was incorrectly specified in the request. This is a common exception generated by the AWS SDK when interacting with S3.
- A. Incorrect.
This is incorrect because the error is related to the object key, not the bucket itself. If the bucket did not exist, a different error, such as 'NoSuchBucket,' would be returned.
- B. Incorrect.
This is incorrect because insufficient permissions would result in an 'AccessDenied' error, not 'NoSuchKey.'
- C. Correct.
This is correct because the 'NoSuchKey' error explicitly indicates that the object key specified in the GetObject request does not exist in the bucket.
- D. Incorrect.
This is incorrect because a timeout error would result in a different exception, such as a 'TimeoutError' or 'ThrottlingException,' not 'NoSuchKey.'