Skip to content

Instantly share code, notes, and snippets.

@tmck-code
Last active August 5, 2021 02:06
Show Gist options
  • Select an option

  • Save tmck-code/9cf417dff8209ccea7daeb0661852cbd to your computer and use it in GitHub Desktop.

Select an option

Save tmck-code/9cf417dff8209ccea7daeb0661852cbd to your computer and use it in GitHub Desktop.
Consume the contents of an SQS queue to file
#!/usr/bin/env python3
import boto3
import json
import sys
from itertools import count
NUMBER_OF_MSGS = 100
REGION, QUEUE_NAME, FPATH = sys.argv[1], sys.argv[2], sys.argv[3]
print(REGION, QUEUE_NAME, FPATH)
queue = boto3.resource('sqs', REGION).get_queue_by_name(QueueName=QUEUE_NAME)
print(queue)
input('all good?')
with open(FPATH, 'w') as ostream:
for i in count():
messages = queue.receive_messages(
MessageAttributeNames=["All"],
MaxNumberOfMessages=NUMBER_OF_MSGS,
)
for message in messages:
print(json.dumps(message), file=ostream)
message.delete()
print(i*NUMBER_OF_MSGS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment