Created
December 19, 2018 21:42
-
-
Save jazlopez/7ed8136a9740eb53ee6d85436e0c968c to your computer and use it in GitHub Desktop.
AWS Restore Messages From DLQ
This file contains 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
# empty apd revos dead letter queue | |
import os | |
import boto3 | |
import logging | |
DLQ="" | |
RESTORE="" | |
client = boto3.client('sqs', | |
aws_access_key_id=os.getenv("AWS_ACCESS_KEY"), | |
aws_secret_access_key=os.getenv("AWS_SECRET_KEY")) | |
try: | |
while True: | |
messages = client.receive_message(QueueUrl=DLQ, MessageAttributeNames=["All"], MaxNumberOfMessages=10) | |
if not messages["Messages"]: | |
break | |
for m in messages["Messages"]: | |
receipt = client.send_message(QueueUrl=RESTORE, | |
MessageBody=m["Body"].rstrip(), | |
MessageAttributes=m["MessageAttributes"]) | |
client.delete_message(QueueUrl=DLQ, ReceiptHandle=m["ReceiptHandle"]) | |
except Exception as e: | |
logging.error(e) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment