DVA-C02 Question 349
Single answerA developer is using the AWS SDK for Python (Boto3) to interact with an S3 bucket. While uploading a file, the application throws an exception indicating that the provided AWS credentials are invalid. Which exception should the developer handle in the code to correctly identify and manage this error?
- A
botocore.exceptions.NoCredentialsError
- B
botocore.exceptions.PartialCredentialsError
- C
botocore.exceptions.ClientError
- D
botocore.exceptions.EndpointConnectionError
Show answer and explanation
Correct answer: B
Explanation
The botocore.exceptions.PartialCredentialsError exception is triggered when the credentials provided to the AWS SDK are incomplete or invalid. Handling this specific exception allows the developer to programmatically identify and resolve credential-related issues, making it the most suitable choice for the given scenario.
- A. Incorrect.
This exception occurs when no credentials are provided, but the error in this scenario is about invalid credentials, not missing ones.
- B. Correct.
This exception is raised when the provided AWS credentials are incomplete or invalid, which matches the scenario described in the question.
- C. Incorrect.
This is a generic exception in the AWS SDK, often used for errors like access denied, invalid parameters, or resource not found. It does not specifically address invalid credentials.
- D. Incorrect.
This exception occurs when the SDK cannot connect to a specified AWS service endpoint, which is unrelated to the credentials issue described in the scenario.