Created
May 30, 2017 16:11
-
-
Save dsaiztc/92df62369ffaa83ec74c9466f208ce88 to your computer and use it in GitHub Desktop.
boto3 error management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
from botocore.exceptions import ClientError as BotoClientError | |
s3_client = boto3.client('s3') | |
s3_bucket = 'randombucket' | |
s3_key = 'randomkey' | |
try: | |
s3_result = s3_client.get_object(Bucket=s3_bucket, Key=s3_key) | |
except BotoClientError as e: | |
error_response = e.response | |
# Example of error_response | |
error_response = { | |
'Error': { | |
'Code': 'NoSuchKey', | |
'Key': 'randomkey', | |
'Message': 'The specified key does not exist.' | |
}, | |
'ResponseMetadata': { | |
'HTTPHeaders': { | |
'content-type': 'application/xml', | |
'date': 'Tue, 30 May 2017 15:57:36 GMT', | |
'server': 'AmazonS3', | |
'transfer-encoding': 'chunked', | |
'x-amz-id-2': '<host-id>', | |
'x-amz-request-id': '8D3DE39D5B618F56' | |
}, | |
'HTTPStatusCode': 404, | |
'HostId': '<host-id>', | |
'RequestId': '8D3DE39D5B618F56', | |
'RetryAttempts': 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment