Skip to content

Instantly share code, notes, and snippets.

@richardgrantserverless
Created May 31, 2022
Embed
What would you like to do?
# reprocess.py
import json
import os
import boto3
from log import logger
from service import handle_record
queue_url = os.environ['DEAD_LETTER_QUEUE']
client = boto3.client('sqs')
while True:
resp = client.receive_messages(QueueUrl=queue_name)
messages = resp.get('Messages')
# If we didn't receive any messages, the queue is empty and we can stop.
if not messages:
break
for message in messages:
body = json.loads(message['Body'])
record = body['record']
try:
handle_record(record)
client.delete_message(
QueueUrl=queue_name,
ReceiptHandle=message.get('ReceiptHandle')
)
except Exception as e:
logger.error(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment