Note that when using boto3, I checked when I wanted to handle errors when reading a non-existent S3 object.
A NoSuchKey error is returned, but it seems to be a dynamically generated exception class and cannot be imported and described in the except clause.
The correspondence method was written in stackoverflow. http://stackoverflow.com/questions/33068055/boto3-python-and-how-to-handle-errors
The following is an excerpt.
import boto3
from botocore.exceptions import ClientError
try:
iam = boto3.client('iam')
user = iam.create_user(UserName='fred')
print "Created user: %s" % user
except ClientError as e:
if e.response['Error']['Code'] == 'EntityAlreadyExists':
print "User already exists"
else:
print "Unexpected error: %s" % e
Catch the exception as ClientError of botocore.exceptions and check the error content with the value of response ['Error'] ['Code'].
Recommended Posts