Skip to content

Instantly share code, notes, and snippets.

@nmagee
Last active July 18, 2017 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmagee/9c54bb4023018965b0c1531fbac254bd to your computer and use it in GitHub Desktop.
Save nmagee/9c54bb4023018965b0c1531fbac254bd to your computer and use it in GitHub Desktop.
A simple example of how to handle boto3 errors using botocore
import boto3
import botocore
import errorsns # A custom SNS handler
def check_queue():
client = boto3.client('sqs', region_name='us-east-1')
req = client.receive_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/123456789012/my-queue',
MessageAttributeNames=[
'JobID',
],
WaitTimeSeconds=20,
MaxNumberOfMessages=1
)['Messages'][0]
global handle, jobid
handle = req['ReceiptHandle']
jobid = req['MessageAttributes']['JobID']['StringValue']
try:
print("The File ID is: %s") % (jobid)
print("The Receipt Handle is: %s") % (handle)
except botocore.exceptions.ClientError as e:
msg = e.response['Error']['Message']
errorsns.send(jobid, msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment