Skip to content

Instantly share code, notes, and snippets.

@patrickpierson
Created May 29, 2019 14:46
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 patrickpierson/5f74cfc86a01615d434562967876d4e4 to your computer and use it in GitHub Desktop.
Save patrickpierson/5f74cfc86a01615d434562967876d4e4 to your computer and use it in GitHub Desktop.
import boto3
sqs_client = boto3.client('sqs')
while True:
with open('messages.txt', 'a') as save_file:
messages = sqs_client.receive_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/1234567890123/example',
MaxNumberOfMessages=10
)
for message in messages.get('Messages'):
save_file.write(message.get('Body') + '\n')
delete_response = sqs_client.delete_message(
QueueUrl='https://sqs.us-east-1.amazonaws.com/1234567890123/example',
ReceiptHandle=message.get('ReceiptHandle')
)
print('Processed %s messages' % len(messages.get('Messages')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment