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)
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.
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.
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.
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.
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')
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With