Created
April 14, 2016 20:09
-
-
Save dkarchmer/3f3578e4c595b2d4d4760f39e9848391 to your computer and use it in GitHub Desktop.
Using Boto3 to process SQS messages
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 | |
# Get the service resource | |
sqs = boto3.resource('sqs') | |
# Get the queue. This returns an SQS.Queue instance | |
queue = sqs.get_queue_by_name(QueueName='my-queue') | |
# You can now access identifiers and attributes | |
logger.info(queue.url) | |
# Process messages | |
for message in queue.receive_messages(VisibilityTimeout=8000, MaxNumberOfMessages=10): | |
# Print out the body and author (if set) | |
payload = json.loads(message.body) | |
for key in payload.keys(): | |
print('{0} = {1}'.format(key, payload[key])) | |
# Let the queue know that the message is processed | |
message.delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment