delete_message.py 444 B

12345678910111213141516171819
  1. import os
  2. import logging
  3. import boto3
  4. from decorators import with_logging
  5. logger = logging.getLogger()
  6. sqs = boto3.resource("sqs")
  7. queue_url = os.getenv("QueueUrl")
  8. @with_logging
  9. def handler(event, context):
  10. receipt_handle = event.get("ReceiptHandle")
  11. if receipt_handle:
  12. message = sqs.Message(queue_url, receipt_handle)
  13. message.delete()
  14. else:
  15. logger.warning("No receipt handle found in event. Skipping")