Skip to content

Instantly share code, notes, and snippets.

@dkarchmer
Created April 14, 2016 20:09
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 dkarchmer/3f3578e4c595b2d4d4760f39e9848391 to your computer and use it in GitHub Desktop.
Save dkarchmer/3f3578e4c595b2d4d4760f39e9848391 to your computer and use it in GitHub Desktop.
Using Boto3 to process SQS messages
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