question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consistent documentation for the ClientError

See original GitHub issue

The ClientError is now (I think?) the gateway to most AWS service exceptions. The documentation around it is not very clear.

Here, we’re checking [‘Error’][‘Code’] for the string 'InvalidInstanceID.NotFound':

from botocore.exceptions import ClientError

ec2 = session.get_client('ec2', 'us-west-2')
try:
    parsed = ec2.describe_instances(InstanceIds=['i-badid'])
except ClientError as e:
    logger.error("Received error: %s", e, exc_info=True)
    # Only worry about a specific service error code
    if e.response['Error']['Code'] == 'InvalidInstanceID.NotFound':
        raise

Here we’re checking it for the string "404". Note int() will throw if any other error is present in that field.

import botocore
bucket = s3.Bucket('mybucket')
exists = True
try:
    s3.meta.client.head_bucket(Bucket='mybucket')
except botocore.exceptions.ClientError as e:
    # If a client error is thrown, then check that it was a 404 error.
    # If it was a 404 error, then the bucket does not exist.
    error_code = int(e.response['Error']['Code'])
    if error_code == 404:
        exists = False
  • Can you provide more guidance on what the field in Error.Code looks like, and how this matches up with exceptions mentioned (but not linked ) in the documentation like LimitExceededException?
  • Is Error.Code guaranteed to always exist for a ClientError, or do I need another level of try/catch error wrapping around that?
  • What other fields exist on ClientError.response, besides Error ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
markddavidoffcommented, Apr 17, 2018

If anyone else ends up here looking for a list of error codes, the ClientError.response['Error']['Code'] error codes come from the aws sdk and can be found here

2reactions
lenucksicommented, Jun 2, 2016

👍

Also a clear documentation of every possible exception dict content at best linked from or included at the location where the said content may occur would be very helpful.

I would also find it very appreciable if you could provide proper, exception classes per service and exception instead of the dict approach. That would allow to use try in a more precise, pythonic way without catching the ClientError blank and then wading around in Exception details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling — Boto3 Docs 1.26.35 documentation - AWS
The most common botocore exception you'll encounter is ClientError . This is a general exception when an error response is provided by an...
Read more >
Error codes for the Amazon EC2 API
This section lists the client error codes that all Amazon EC2 API actions can return. ... For more information, see Eventual consistency.
Read more >
Error Codes - Aerospike Documentation
Here are the error code tables for some of the main client libraries: Java Client Error Code. C# Client Error Code. C Client...
Read more >
Amazon SageMaker Clarify Model Monitors
See the documentation for how to fine tune the permissions needed. ... to get consistent results rand = random.random() # format required by...
Read more >
API Reference - DataRobot Python package documentation
Returns: list of BlueprintTaskDocument. All documents available for blueprint. ... CalendarFile.get(some_calendar_id) >>> ClientError: Item not found.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found