I have a lambda configured to a DLQ that may have a few messages in a day. I'm using java for lambda function. My Handler class and method looks something like this:
public class LambdaMethodHandler implements RequestHandler<SQSEvent, String> {
@Override
public String handleRequest(SQSEvent event, Context context){
context.getLogger().log("Started processing messages in DLQ");
List<String> failedMessages = new ArrayList<>();
event.getRecords().stream().forEach(message -> {
context.getLogger().log("Message body: "+message.getBody()+", Message sent on: "+message.getMessageAttributes().get("timestamp")+", Message ID: "+message.getMessageId());
failedMessages.add(message.getBody());
});
The idea was to trigger this lambda once a day using EventBridge and if there are multiple messages in the DLQ, it should iterate through them and save it in a file. So I assumed that in SQSEvent the records field is a List so ideally if there are multiple messages in the DLQ then these messages will be passed as List<SQSMessage> records in the SQSEvent. But as I was testing(for now by manually adding messages to the DLQ before configuring the lambda), if there were multiple messages, it would just trigger the lambda multiple time.
Not sure if I've understood the concept incorrectly or is there something wrong with my implementation.