Search code examples
amazon-web-servicesamazon-sqs

Amazon AWS SQS queue message retention period


This is a 3 part question :

  1. I understand that the message retention period for an SQS queue can be set to a maximum of 14 days. I could not find a definite answer to whether you can also decrease the period back to a lesser value.

  2. Consider the queue (original retention period of 4 days) has following messages at the very moment I set the message retention period to 14 days :

    a. 10 messages in queue
    b. 2 messages in flight

    How will this newly set retention period apply to these messages ? Do the 10 messages already in the queue still get deleted after 4 days or they will also be retained for 14 days ?
    If the 2 messages in flight are returned to the queue (made visible again) will they be retained for 14 days from the time they were first received in the queue ?

  3. If the current retention period of the queue is 14 days, there is a message in the queue that has been there for 5 days. Now if I decrease the retention period to 4 days, what happens to this message ?


Solution

  • As per the AWS Docs here the retention period of a message can be set to between 1 minute and 14 days.

    Before I address the main question, in-flight messages are messages that have already been received by a queue consumer, but have not yet been and are already being processed. Changes to the queue itself should have no effect on already in-flight messages as technically they are no longer visible.

    Regarding updating queue configurations. When you update the retention policy of a SQS Queue, messages already in the queue retain the retention policy of the queue that existed at the time those messages were added, and new messages will receive the retention policy that is effective from that point forward.

    In your point 2 above, if you have 10 messages in the queue with a retention period of 4 days, and you update the queue to 14 days, existing messages will retain the 4 day retention policy, while new messages will have the 14 day retention policy applied. For point 3 above, the same principal applies when adjusting the queue the other way. If you have some messages that have a 14 day retention policy and you change the queue policy to be 4 days then the messages added to the queue when the retention policy was 14 days will retain the 14 day retention policy, and new messages will receive the 4 day retention policy.