Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Delete SQS queue

Is there a way to auto delete SQS queues entirely. I have a solution wherein a server on startup creates an SQS and subscribes to SNS topic.

However there maybe scenarios wherein the server crashes and is irrecoverable. In such cases, I would replace the server with a different one which would create its own queue on startup. Now the earlier queue is not going to be used anymore.

Is there a way to for the queue to get auto-deleted with me going and deleting it explicitly (maybe like if the queue remains empty for 5 days, it gets auto deleted or some other alternative)?

like image 493
alwaysAStudent Avatar asked Jan 12 '18 03:01

alwaysAStudent


1 Answers

At the moment, AWS SQS does not provide a mechanism to automatically delete a queue when it is empty for a certain number of days. Even I feel like this is a needed feature. But there are ways to tackle this problem.

Mentioned below, are a few ways to delete the AWS SQS according to the scenario in your question. You can select which suits you the most.

  1. Maintain a small Database Table which keeps the mapping between the Server IP and Queue URL. You can insert values into this table, when a server starts itself. Maintain a Cloudwatch Rule that will invoke a Lambda, which will go through the values in the table to see if the server is running or not (probably by a heartbeat). If a particular server is not running, simply get the related SQS URL and delete that specific Queue. (I have suggested Lambda here because it is cheap)

sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl));

  1. Whenever a Server is started, it can send an Email to a person with the Server IP and SQS URL using SNS. Using a CloudWatch Rule, invoke a Lambda from time to time, and get all Instances, and check if any instance is down. If an instance is down, send an email to the relevant person using SNS, emailing that this server is down. It is semi-automatic, where the use can manually delete the queue after seeing the email.

  2. Simply let the Empty queues be on its own. There is no limit as to how many queues can be made inside AWS. So why bother to delete them if that process is hard. Simply create new Queue as you go along. (See: No Max number of SQS Queue Limitation)

like image 188
Keet Sugathadasa Avatar answered Oct 09 '22 01:10

Keet Sugathadasa