Botocore

broken image


Botocore pypi

Parsing error responses and catching exceptions from AWS services¶

Botocore
Botocore

Botocore is the foundation that underpins the AWS CLI and also Boto 3, while Boto 3 is the official python SDK for AWS. As others have said, Boto3 provides a cleaner API which will make your code more readable. Consider the following example usage, both examples achieve the same result but Boto 3 does it with fewer lines and fewer characters. Botocore.exceptions.NoRegionError: You must specify a region.my config file↓ is located in the same folder as my credentails. default ap-northeast-1 – d-b Oct 24 '15 at 14:55 1.

Unlike botocore exceptions, AWS service exceptions aren't statically defined in Boto3. This is due to errors and exceptions from AWS services varying widely and being subject to change. To properly catch an exception from an AWS service, you must parse the error response from the service. The error response provided to your client from the AWS service follows a common structure and is minimally processed and not obfuscated by Boto3.

Using Boto3, the error response from an AWS service will look similar to a success response, except that an Error nested dictionary will appear with the ResponseMetadata nested dictionary. Here is an example of what an error response might look like:

Boto3 classifies all AWS service errors and exceptions as ClientError exceptions. When attempting to catch AWS service exceptions, one way is to catch ClientError and then parse the error response for the AWS service-specific exception.

Using Amazon Kinesis as an example service, you can use Boto3 to catch the exception LimitExceededException and insert your own logging message when your code experiences request throttling from the AWS service.

Note

The Boto3 standard retry mode will catch throttling errors and exceptions, and will back off and retry them for you.

Botocore Config

Botocore

Parsing error responses and catching exceptions from AWS services¶

Botocore is the foundation that underpins the AWS CLI and also Boto 3, while Boto 3 is the official python SDK for AWS. As others have said, Boto3 provides a cleaner API which will make your code more readable. Consider the following example usage, both examples achieve the same result but Boto 3 does it with fewer lines and fewer characters. Botocore.exceptions.NoRegionError: You must specify a region.my config file↓ is located in the same folder as my credentails. default ap-northeast-1 – d-b Oct 24 '15 at 14:55 1.

Unlike botocore exceptions, AWS service exceptions aren't statically defined in Boto3. This is due to errors and exceptions from AWS services varying widely and being subject to change. To properly catch an exception from an AWS service, you must parse the error response from the service. The error response provided to your client from the AWS service follows a common structure and is minimally processed and not obfuscated by Boto3.

Using Boto3, the error response from an AWS service will look similar to a success response, except that an Error nested dictionary will appear with the ResponseMetadata nested dictionary. Here is an example of what an error response might look like:

Boto3 classifies all AWS service errors and exceptions as ClientError exceptions. When attempting to catch AWS service exceptions, one way is to catch ClientError and then parse the error response for the AWS service-specific exception.

Using Amazon Kinesis as an example service, you can use Boto3 to catch the exception LimitExceededException and insert your own logging message when your code experiences request throttling from the AWS service.

Note

The Boto3 standard retry mode will catch throttling errors and exceptions, and will back off and retry them for you.

Botocore Config

Additionally, you can also access some of the dynamic service-side exceptions from the client's exception property. Using the previous example, you would need to modify only the except clause.

Note

Botocore Pypi

Catching exceptions through ClientError and parsing for error codes is still the best way to catch all service-side exceptions and errors.





broken image