Python‎ > ‎

handling errors & exceptions when using Boto3

posted Jun 20, 2020, 1:15 PM by Chris G   [ updated Jun 20, 2020, 1:16 PM ]

New to AWS & Boto3? Learn the best practices for handling errors & exceptions when using Boto3, the AWS SDK for Python:


AWS services require clients to use a variety of parameters, behaviors, or limits when interacting with their APIs. Boto3 provides many features to assist in navigating the errors and exceptions that you might encounter when interacting with AWS services.

Specifically, this guide provides details on the following:

  • How to find what exceptions there are to catch when using Boto3 and interacting with AWS services
  • How to catch/handle exceptions thrown by both Boto3 and AWS services
  • How to parse error responses from AWS services

Why catch exceptions from AWS and Boto

  • Retries - Your call rate to an AWS service might be too frequent, or you might have reached a specific AWS service quota. In either case, without proper error handling you wouldn’t know or wouldn’t handle them.
  • Parameter validation/checking - API requirements can change, especially across API versions. Catching these errors helps to identify if there’s an issue with the parameters you provide to any given API call.
  • Proper logging/messaging - Catching errors and exceptions means you can log them. This can be instrumental in troubleshooting any code you write when interacting with AWS services.

Determining what exceptions to catch

Exceptions that you might encounter when using Boto3 will come from one of two sources: botocore or the AWS services your client is interacting with.

Botocore exceptions

These exceptions are statically defined within the botocore package, a dependency of Boto3. The exceptions are related to issues with client-side behaviors, configurations, or validations. You can generate a list of the statically defined botocore exceptions using the following code:

import botocore.exceptions

for key, value in sorted(botocore.exceptions.__dict__.items()):
    if isinstance(value, type):