Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
Created May 30, 2017 16:11
Show Gist options
  • Save dsaiztc/92df62369ffaa83ec74c9466f208ce88 to your computer and use it in GitHub Desktop.
Save dsaiztc/92df62369ffaa83ec74c9466f208ce88 to your computer and use it in GitHub Desktop.
boto3 error management
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