Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to look-up what exceptions a BOTO3 function can throw?

I’m reading AWS Python docs such as SNS Client Publish() but can’t find the details of what exceptions a function can throw.

E.g., publish() can throw EndpointDisabledException but I can’t find this documented.

Where can I look up the list of exceptions a BOTO3 function can throw (for Python)

like image 662
Carl Avatar asked Oct 22 '17 09:10

Carl


People also ask

How to handle exception in Boto3?

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.

How do you catch errors in Python?

The try block lets you test a block of code for errors. The except block lets you handle the error. The else block lets you execute code when there is no error. The finally block lets you execute code, regardless of the result of the try- and except blocks.

What is Botocore?

Botocore is a low-level interface to a growing number of Amazon Web Services. Botocore serves as the foundation for the AWS-CLI command line utilities. It will also play an important role in the boto3. x project. The botocore package is compatible with Python versions Python 3.7 and higher.

What is Boto3 resource?

Boto3 resource is a high-level object-oriented API service you can use to connect and access your AWS resource. It has actions() defined which can be used to make calls to the AWS service.


2 Answers

This is how to handle such exceptions:

import boto3
from botocore.exceptions import ClientError
import logging

try:
    response = platform_endpoint.publish(
        Message=json.dumps(message, ensure_ascii=False),
        MessageStructure='json')
    logging.info("r = %s" % response)
except ClientError as e:
    if e.response['Error']['Code'] == 'EndpointDisabled':
        logging.info('EndpointDisabledException thrown')
like image 171
Carl Avatar answered Nov 25 '22 03:11

Carl


Almost all exceptions are subclassed from BotoCoreError. I am not able to find a method to list all exceptions. Look at Botocore Exceptions file to get a list of possible exceptions. I can't find EndpointDisabledException. Are you using the latest version?

See: Botocore Exceptions

like image 24
helloV Avatar answered Nov 25 '22 03:11

helloV