Last active
August 5, 2021 02:06
-
-
Save tmck-code/9cf417dff8209ccea7daeb0661852cbd to your computer and use it in GitHub Desktop.
Consume the contents of an SQS queue to file
This file contains hidden or 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
| #!/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