Skip to content

Commit 4642e2e

Browse files
author
sourabh
committed
changes as per review comments in the GITHUB PR.
1 parent 4f144dd commit 4642e2e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

loggroup-lambda-connector/sam/template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Resources:
203203
Resource:
204204
- !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${SumoLogGroupLambdaConnector}'
205205

206-
primerinvoke:
206+
InvokeLambdaConnector:
207207
Type: AWS::CloudFormation::CustomResource
208208
Version: "1.0"
209209
Condition: invoke_existing

loggroup-lambda-connector/src/loggroup-lambda-connector.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var AWS = require("aws-sdk");
22
const util = require("util");
33
var cwl = new AWS.CloudWatchLogs({apiVersion: '2014-03-28'});
4+
var maxRetryCounter = 3;
45

56
async function createSubscriptionFilter(lambdaLogGroupName, destinationArn, roleArn) {
67
if (destinationArn.startsWith("arn:aws:lambda")){
@@ -53,7 +54,7 @@ function filterLogGroups(event, logGroupRegex) {
5354
return false;
5455
}
5556

56-
async function subscribeExistingLogGroups(logGroups, counter) {
57+
async function subscribeExistingLogGroups(logGroups, retryCounter) {
5758
var logGroupRegex = new RegExp(process.env.LOG_GROUP_PATTERN, "i");
5859
var destinationArn = process.env.DESTINATION_ARN;
5960
var roleArn = process.env.ROLE_ARN;
@@ -73,9 +74,9 @@ async function subscribeExistingLogGroups(logGroups, counter) {
7374
}
7475
}, Promise.resolve());
7576

76-
if (counter < 4 && failedLogGroupNames.length > 0) {
77-
console.log("Retrying Subscription for Failed Log Groups due to throttling with counter number as " + counter);
78-
await subscribeExistingLogGroups(failedLogGroupNames, counter + 1);
77+
if (retryCounter <= maxRetryCounter && failedLogGroupNames.length > 0) {
78+
console.log("Retrying Subscription for Failed Log Groups due to throttling with counter number as " + retryCounter);
79+
await subscribeExistingLogGroups(failedLogGroupNames, retryCounter + 1);
7980
}
8081
}
8182

@@ -100,7 +101,7 @@ function processExistingLogGroups(token, context, errorHandler) {
100101
});
101102
});
102103
var cb = async function (data) {
103-
await subscribeExistingLogGroups(data.logGroups, 0);
104+
await subscribeExistingLogGroups(data.logGroups, 1);
104105
if (data.nextToken) {// if next set of log groups exists, invoke next instance of lambda
105106
console.log("Log Groups remaining...Calling the lambda again with token " + data.nextToken);
106107
invoke_lambda(context, data.nextToken, errorHandler);

0 commit comments

Comments
 (0)