You are using AWS SQS managed FIFO message queuing service that enables you to decouple and scale microservices. Now you observe that sometimes the messages are not processed (for different reasons) and these messages are dumped in the Dead letter FIFO message queue configured for the source FIFO queue. Order of messages is no problem for your application so you want these messages to be relayed back to the source queue. To do so there are different options available-
- Setup a Lambda function that could automate this process. Automate using Lambda
- But if you want to review the message to find the cause for not getting processed before it is replayed then you can set up a replay of the message as the manual process by creating a pipeline on GitLab. In this article, I will share the scripts and steps to do this.
- There could be some other better option which I am not aware of as yet.
1. Setup Queues and IAM user (skip this step if you already have source queue, DLQ queue, and IAM user having access to these queues).
>> Login to AWS console and select SQS service to create Source FIFO queue. Follow the screenshot highlights to create the FIFO queue-
>> Now create a DLQ queue for the source queue and then configure the Source queue with the DLQ queue. Follow the screenshots-
After creating DLQ queue, edit the source queue (source_queue.fifo) to configure with DLQ queue and Save
>> Create IAM SQS access policy and attach to a user (as shown in screenshots)-
Using this JSON policy create an IAM policy (DO CHANGE the RED highlighted account number).
Create an IAM user and attach this policy. Note the AWS security credentials (
AWS_SECRET_ACCESS_KEY). We will need it to set up in GitLab.
2. Now Create a GitLab repository, pipeline, and configure variables.
>> Create a GitLab repository and place these files in it.
aws-sqs-replay-msg.py (you can change the AWS region as per yours)
AWS_SECRET_ACCESS_KEY) as project settings-
Now the GitLab pipeline is set up and ready to run. Create some messages for the source queue and force them to the DLQ queue for testing. Run the GitLab pipeline manually and see that the messages from the DLQ queue are replayed to the source queue and removed from the DLQ queue.