Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
fix(sqs): add total_record_count in SQS trigger lambda (#464)
Browse files Browse the repository at this point in the history
* fix(sqs): add total_record_count in SQS trigger lambda

* fix(sqs): improve metadata info for 2 methods

Co-authored-by: Daniele Frasca <[email protected]>
Co-authored-by: Ran Ribenzaft <[email protected]>
  • Loading branch information
3 people authored Mar 18, 2021
1 parent e6ffae6 commit 6aa1922
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/events/aws_sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,39 @@ 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, {
'Message ID': `${response.data.MessageId}`,
'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)) {
Expand Down
1 change: 1 addition & 0 deletions src/triggers/aws_lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function createSQSTrigger(event, trigger) {
}
return record;
}),
total_record_count: event.Records.length,
});
try {
const messageBody = JSON.parse(sqsMessageBody);
Expand Down

0 comments on commit 6aa1922

Please sign in to comment.