9
votes

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)

4

4 Answers

8
votes

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')
6
votes

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

0
votes

Use the client and then find the exception

example : if we are dealing with the cognito then

client = boto3.client(
        'cognito-idp',....)
try:
   some code .......
except client.exceptions.UsernameExistsException as ex:
    print(ex)
0
votes

you can find the list of exceptions for publish(**kwargs) -> here <- (bottom of publish(**kwargs) part)

Every exception is linked to its documentation

SNS.Client.exceptions.InvalidParameterException
SNS.Client.exceptions.InvalidParameterValueException
SNS.Client.exceptions.InternalErrorException
SNS.Client.exceptions.NotFoundException
SNS.Client.exceptions.EndpointDisabledException
SNS.Client.exceptions.PlatformApplicationDisabledException
SNS.Client.exceptions.AuthorizationErrorException
SNS.Client.exceptions.KMSDisabledException
SNS.Client.exceptions.KMSInvalidStateException
SNS.Client.exceptions.KMSNotFoundException
SNS.Client.exceptions.KMSOptInRequired
SNS.Client.exceptions.KMSThrottlingException
SNS.Client.exceptions.KMSAccessDeniedException
SNS.Client.exceptions.InvalidSecurityException