How to handle errors with boto3?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Good Boto3 error handling starts with one practical fact: most AWS service failures arrive as ClientError, not as a long list of service-specific exception classes. That means robust code usually catches ClientError, inspects the AWS error code, and then decides whether the failure is expected, retryable, or fatal. If you skip that inspection step, your AWS automation becomes noisy and hard to trust.
Know the Main Error Categories
In day-to-day Boto3 code, you will most often see:
- '
ClientErrorfor service responses such asNoSuchBucketorAccessDenied' - '
ParamValidationErrorfor invalid request parameters before the request is sent' - broader botocore exceptions for transport or configuration problems
A practical import pattern looks like this:
That gives you enough coverage for most application code.
Handle ClientError by Inspecting the Error Code
This is the most common pattern.
Why inspect exc.response["Error"]["Code"]:
- AWS services use structured error codes
- the same Python exception type can represent many distinct service outcomes
- application logic usually depends on the AWS code, not the Python class name alone
Example: Expected "Not Found" Versus Real Failure
Sometimes a missing resource is a normal condition, not an outage.
This pattern is better than catching every exception and returning False, because permission errors and network problems should not be silently treated as "missing resource."
Catch Parameter Errors Separately
Some failures happen before any AWS request is even sent.
This is a different class of bug from a service-side failure and should usually be fixed, not retried.
Log Context, Not Just the Exception String
A bare exception string is often not enough for debugging. Log the operation, the key identifiers, and the AWS error code.
That kind of log line is much more actionable in production.
Retries Need Judgment
Not every Boto3 error should be retried.
Usually retryable:
- throttling
- transient network failures
- some temporary service-side issues
Usually not retryable:
- access denied
- validation problems
- missing required resources when your workflow assumes they must exist
The real skill is classifying the failure correctly before adding retry loops.
A Reusable Wrapper Pattern
This kind of wrapper is useful when you want consistent error translation at service boundaries in your application.
Common Pitfalls
- Catching
Exceptionbroadly and losing the structured AWS error details. - Treating every
ClientErroras identical instead of checking the AWS error code. - Returning fallback values for permission or throttling failures that should surface explicitly.
- Retrying validation errors that are never going to succeed.
- Logging only the exception string without the operation context.
Summary
- Most AWS service failures in Boto3 arrive as
ClientError. - Inspect
exc.response["Error"]["Code"]to decide how to handle the failure. - Separate parameter-validation problems from service-side errors.
- Log AWS operation context along with the error code.
- Retry only the failures that are actually transient.
Related reading
- How to handle fields enclosed within quotesCSV in importing data from S3 into DynamoDB using EMR/Hive
- How to handle many to many in DynamoDB
- How to handle S3 events inside a Kubernetes Cluster?
- How to handle UnprocessedItems using AWS JavaScript SDK dynamoDB?
- How to handle missing NaNs for machine learning in python
- How to handle multiple results from a coroutine function?
- How to handle exceptions raised in other threads when unit testing?
- How to handle git gc fatal bad object refs/remotes/origin/HEAD error?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.