Last active
July 18, 2017 14:08
-
-
Save nmagee/9c54bb4023018965b0c1531fbac254bd to your computer and use it in GitHub Desktop.
A simple example of how to handle boto3 errors using botocore
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 | |
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