From 6aa1922dc221c9997ecb1b4321a5a6c73df66c5a Mon Sep 17 00:00:00 2001 From: Dan <78874812+ymwjbxxq@users.noreply.github.com> Date: Thu, 18 Mar 2021 08:31:17 +0100 Subject: [PATCH] fix(sqs): add total_record_count in SQS trigger lambda (#464) * fix(sqs): add total_record_count in SQS trigger lambda * fix(sqs): improve metadata info for 2 methods Co-authored-by: Daniele Frasca Co-authored-by: Ran Ribenzaft --- src/events/aws_sdk.js | 26 ++++++++++++++++++++++++++ src/triggers/aws_lambda.js | 1 + 2 files changed, 27 insertions(+) diff --git a/src/events/aws_sdk.js b/src/events/aws_sdk.js index 35554d31..20136eec 100644 --- a/src/events/aws_sdk.js +++ b/src/events/aws_sdk.js @@ -203,6 +203,8 @@ const SQSEventCreator = { * @param {proto.event_pb.Event} event The event to update the data on */ responseHandler(response, event) { + let errorMessages = ''; + let errorMessagesCount = 0; switch (response.request.operation) { case 'sendMessage': eventInterface.addToMetadata(event, { @@ -210,6 +212,30 @@ const SQSEventCreator = { 'MD5 Of Message Body': `${response.data.MD5OfMessageBody}`, }); break; + case 'sendMessageBatch': + if (response.data.Failed && response.data.Failed > 0) { + errorMessages = JSON.stringify(response.data.Failed + .map(item => item)); + errorMessagesCount = response.data.FailedRecordCount; + } + eventInterface.addToMetadata(event, { + successful_record_count: `${response.data.Successful.length}`, + failed_record_count: `${errorMessagesCount}`, + sqs_error_messages: errorMessages, + }); + break; + case 'deleteMessageBatch': + if (response.data.Failed && response.data.Failed > 0) { + errorMessages = JSON.stringify(response.data.Failed + .map(item => item)); + errorMessagesCount = response.data.FailedRecordCount; + } + eventInterface.addToMetadata(event, { + successful_record_count: `${response.data.Successful.length}`, + failed_record_count: `${errorMessagesCount}`, + sqs_error_messages: errorMessages, + }); + break; case 'receiveMessage': { let messagesNumber = 0; if (('Messages' in response.data) && (response.data.Messages.length > 0)) { diff --git a/src/triggers/aws_lambda.js b/src/triggers/aws_lambda.js index 997b58eb..47008716 100644 --- a/src/triggers/aws_lambda.js +++ b/src/triggers/aws_lambda.js @@ -125,6 +125,7 @@ function createSQSTrigger(event, trigger) { } return record; }), + total_record_count: event.Records.length, }); try { const messageBody = JSON.parse(sqsMessageBody);