有没有办法完全自动删除SQS队列。我有一个解决方案,其中启动时的服务器创建SQS并订阅SNS主题。
然而,可能存在服务器崩溃且无法恢复的情况。在这种情况下,我会用不同的服务器替换服务器,这将在启动时创建自己的队列。现在不再使用早期的队列了。
有没有办法让队列自动删除并明确删除它(如果队列在5天内保持为空,它会被自动删除或其他一些替代方案)?
答案 0 :(得分:1)
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.
sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl));
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.
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)
答案 1 :(得分:0)
没有任何方法可以自动删除队列。您可以使用标签来标记已连接的资源(即,标签队列或其他资源在创建时带有其各自的实例ID),并可以使用简单的脚本读取该标签,如果该实例ID不存在,则将其删除。
这是在cli上的方法: https://docs.aws.amazon.com/cli/latest/reference/sqs/tag-queue.html
(我假设服务器是指EC2实例。也可以使用IP)