Skip to content

Commit 23cbb63

Browse files
authored
Merge pull request #172 from SumoLogic/python-js-update
Updating runtimes of python and nodeJS
2 parents 7412937 + 57d5272 commit 23cbb63

15 files changed

+288
-266
lines changed

awsautoenableS3Logging/packaged.yaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Metadata:
2424
- s3logging
2525
- flowlogs
2626
Name: sumologic-s3-logging-auto-enable
27-
SemanticVersion: 1.0.5
27+
SemanticVersion: 1.0.6
2828
SourceCodeUrl: https://github.com/SumoLogic/sumologic-aws-lambda/tree/master/awsautoenableS3Logging
29-
LicenseUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.5/978602b5b9ec16f8bab0e38fd6b3998f
30-
ReadmeUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.5/d05d411471e0bb4db3389f2523f515f0
29+
LicenseUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.6/978602b5b9ec16f8bab0e38fd6b3998f
30+
ReadmeUrl: s3://appdevstore/AutoEnableS3Logs/v1.0.6/d05d411471e0bb4db3389f2523f515f0
3131
SpdxLicenseId: Apache-2.0
3232
Mappings:
3333
Region2ELBAccountId:
@@ -221,9 +221,9 @@ Resources:
221221
Type: AWS::Serverless::Function
222222
Condition: auto_enable_new
223223
Properties:
224-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.10/sumo_app_utils.zip
224+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.11/sumo_app_utils.zip
225225
Handler: awsresource.enable_s3_logs
226-
Runtime: python3.7
226+
Runtime: python3.11
227227
Role:
228228
Fn::GetAtt:
229229
- SumoLambdaRole
@@ -458,8 +458,8 @@ Resources:
458458
Condition: auto_enable_existing
459459
Properties:
460460
Handler: main.handler
461-
Runtime: python3.7
462-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.10/sumo_app_utils.zip
461+
Runtime: python3.11
462+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.11/sumo_app_utils.zip
463463
MemorySize: 128
464464
Timeout: 900
465465
Role:

awsautoenableS3Logging/sumologic-s3-logging-auto-enable.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Metadata:
2424
- s3logging
2525
- flowlogs
2626
Name: sumologic-s3-logging-auto-enable
27-
SemanticVersion: 1.0.5
27+
SemanticVersion: 1.0.6
2828
SourceCodeUrl: https://github.com/SumoLogic/sumologic-aws-lambda/tree/master/awsautoenableS3Logging
2929
LicenseUrl: ./LICENSE
3030
ReadmeUrl: ./README.md
@@ -204,9 +204,9 @@ Resources:
204204
Type: 'AWS::Serverless::Function'
205205
Condition: auto_enable_new
206206
Properties:
207-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.10/sumo_app_utils.zip
207+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.11/sumo_app_utils.zip
208208
Handler: "awsresource.enable_s3_logs"
209-
Runtime: python3.7
209+
Runtime: python3.11
210210
Role: !GetAtt SumoLambdaRole.Arn
211211
Description: "Lambda Function for auto enable s3 logs for AWS Resources."
212212
MemorySize: 128
@@ -380,8 +380,8 @@ Resources:
380380
Condition: auto_enable_existing
381381
Properties:
382382
Handler: main.handler
383-
Runtime: python3.7
384-
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.10/sumo_app_utils.zip
383+
Runtime: python3.11
384+
CodeUri: s3://appdevstore/sumo_app_utils/v2.0.11/sumo_app_utils.zip
385385
MemorySize: 128
386386
Timeout: 900
387387
Role:

cloudwatchlogs-with-dlq/DLQLambdaCloudFormation.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
"FunctionName": { "Fn::Join": [ "-", [ "SumoCWLogsLambda", { "Fn::Select" : [ "2", {"Fn::Split" : [ "/" , { "Ref": "AWS::StackId" } ]}] } ] ] },
211211
"Code": {
212212
"S3Bucket": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "bucketname"]},
213-
"S3Key": "cloudwatchlogs-with-dlq.zip"
213+
"S3Key": "cloudwatchLogsDLQ/v1.2.0/cloudwatchlogs-with-dlq.zip"
214214
},
215215
"Role": {
216216
"Fn::GetAtt": [
@@ -228,7 +228,7 @@
228228
}
229229
},
230230
"Handler": "cloudwatchlogs_lambda.handler",
231-
"Runtime": "nodejs16.x",
231+
"Runtime": "nodejs18.x",
232232
"MemorySize": 128,
233233
"Environment": {
234234
"Variables": {
@@ -272,7 +272,7 @@
272272
"FunctionName": { "Fn::Join": [ "-", [ "SumoCWProcessDLQLambda", { "Fn::Select" : [ "2", {"Fn::Split" : [ "/" , { "Ref": "AWS::StackId" } ]}] } ] ] },
273273
"Code": {
274274
"S3Bucket": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "bucketname"]},
275-
"S3Key": "cloudwatchlogs-with-dlq.zip"
275+
"S3Key": "cloudwatchLogsDLQ/v1.2.0/cloudwatchlogs-with-dlq.zip"
276276
},
277277
"Role": {
278278
"Fn::GetAtt": [
@@ -290,7 +290,7 @@
290290
]
291291
}
292292
},
293-
"Runtime": "nodejs16.x",
293+
"Runtime": "nodejs18.x",
294294
"MemorySize": 128,
295295
"Environment": {
296296
"Variables": {

cloudwatchlogs-with-dlq/DLQLambdaCloudFormationWithSecuredEndpoint.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
"FunctionName": { "Fn::Join": [ "-", [ "SumoCWLogsLambda", { "Fn::Select" : [ "2", {"Fn::Split" : [ "/" , { "Ref": "AWS::StackId" } ]}] } ] ] },
253253
"Code": {
254254
"S3Bucket": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "bucketname"]},
255-
"S3Key": "cloudwatchlogs-with-dlq.zip"
255+
"S3Key": "cloudwatchLogsDLQ/v1.2.0/cloudwatchlogs-with-dlq.zip"
256256
},
257257
"Role": {
258258
"Fn::GetAtt": [
@@ -270,7 +270,7 @@
270270
}
271271
},
272272
"Handler": "cloudwatchlogs_lambda.handler",
273-
"Runtime": "nodejs16.x",
273+
"Runtime": "nodejs18.x",
274274
"MemorySize": 128,
275275
"Environment": {
276276
"Variables": {
@@ -313,7 +313,7 @@
313313
"FunctionName": { "Fn::Join": [ "-", [ "SumoCWProcessDLQLambda", { "Fn::Select" : [ "2", {"Fn::Split" : [ "/" , { "Ref": "AWS::StackId" } ]}] } ] ] },
314314
"Code": {
315315
"S3Bucket": { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "bucketname"]},
316-
"S3Key": "cloudwatchlogs-with-dlq.zip"
316+
"S3Key": "cloudwatchLogsDLQ/v1.2.0/cloudwatchlogs-with-dlq.zip"
317317
},
318318
"Role": {
319319
"Fn::GetAtt": [
@@ -331,7 +331,7 @@
331331
]
332332
}
333333
},
334-
"Runtime": "nodejs16.x",
334+
"Runtime": "nodejs18.x",
335335
"MemorySize": 128,
336336
"Environment": {
337337
"Variables": {
+49-44
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,82 @@
1-
var AWS = require("aws-sdk");
2-
var processLogsHandler = require('./cloudwatchlogs_lambda').processLogs;
3-
var getEndpointURL = require('./cloudwatchlogs_lambda').getEndpointURL;
4-
var DLQUtils = require("./sumo-dlq-function-utils").DLQUtils;
5-
var Messages = DLQUtils.Messages;
6-
var invokeLambdas = DLQUtils.invokeLambdas;
1+
const { processLogs: processLogsHandler, getEndpointURL } = require('./cloudwatchlogs_lambda');
2+
const { DLQUtils } = require("./sumo-dlq-function-utils");
3+
4+
const { Messages, invokeLambdas } = DLQUtils;
75

86
exports.consumeMessages = async function (env, context, callback) {
9-
var sqs = new AWS.SQS({region: env.AWS_REGION});
10-
var MessagesObj = new Messages(env);
11-
env.SUMO_CLIENT_HEADER="dlq-aws-lambda";
7+
const MessagesObj = new Messages(env);
8+
env.SUMO_CLIENT_HEADER = "dlq-aws-lambda";
9+
1210
if (!env.SUMO_ENDPOINT) {
13-
let SUMO_ENDPOINT = await getEndpointURL();
14-
if (SUMO_ENDPOINT instanceof Error) {
15-
console.log("Error in getEndpointURL: ", SUMO_ENDPOINT);
16-
callback(SUMO_ENDPOINT, null);
11+
try {
12+
let SUMO_ENDPOINT = await getEndpointURL();
13+
env.SUMO_ENDPOINT = SUMO_ENDPOINT;
14+
} catch (error) {
15+
console.log("Error in getEndpointURL: ", error);
16+
callback(error, null);
1717
return;
1818
}
19-
env.SUMO_ENDPOINT = SUMO_ENDPOINT;
2019
} else {
2120
console.log("consumeMessages: Getting SUMO_ENDPOINT from env");
2221
}
23-
MessagesObj.receiveMessages(10, function (err, data) {
24-
var messages = (data)? data.Messages: null;
25-
if (err) {
26-
callback(err);
27-
} else if (messages && messages.length > 0) {
28-
var fail_cnt = 0, msgCount = 0;
22+
23+
try {
24+
const messages = await MessagesObj.receiveMessages(10);
25+
26+
27+
if (messages && messages.length > 0) {
28+
let fail_cnt = 0, msgCount = 0;
2929
console.log("Messages Received", messages.length);
30-
for (var i = 0; i < messages.length; i++) {
31-
(function(idx) {
32-
var payload = JSON.parse(messages[idx].Body);
33-
var receiptHandle = messages[idx].ReceiptHandle;
30+
31+
for (let i = 0; i < messages.length; i++) {
32+
(function (idx) {
33+
const payload = JSON.parse(messages[idx].Body);
34+
const receiptHandle = messages[idx].ReceiptHandle;
35+
3436
if (!(payload.awslogs && payload.awslogs.data)) {
3537
console.log("Message does not contain awslogs or awslogs.data attributes", payload);
36-
//deleting msg in DLQ after injesting in sumo
37-
MessagesObj.deleteMessage(receiptHandle, function (err, data) {
38-
if (err) console.log(err, err.stack);
39-
});
38+
39+
MessagesObj.deleteMessage(receiptHandle)
40+
.catch((err) => console.log(err, err.stack));
41+
4042
return;
4143
}
42-
var logdata = payload.awslogs.data;
44+
45+
const logdata = payload.awslogs.data;
46+
4347
processLogsHandler(env, logdata, function (err, msg) {
4448
msgCount++;
49+
4550
if (err) {
4651
console.log(err, msg);
4752
fail_cnt++;
4853
} else {
49-
//deleting msg in DLQ after injesting in sumo
50-
MessagesObj.deleteMessage(receiptHandle, function (err, data) {
51-
if (err) console.log(err, err.stack);
52-
});
54+
MessagesObj.deleteMessage(receiptHandle)
55+
.catch((err) => console.log(err, err.stack));
5356
}
54-
if (msgCount == messages.length) {
55-
if (fail_cnt == 0 && (parseInt(env.is_worker) === 0)) {
57+
58+
if (msgCount === messages.length) {
59+
if (fail_cnt === 0 && parseInt(env.is_worker) === 0) {
5660
invokeLambdas(env.AWS_REGION, parseInt(env.NUM_OF_WORKERS),
57-
context.functionName, '{"is_worker": "1"}', context);
61+
context.functionName, '{"is_worker": "1"}', context);
5862
}
59-
callback(null, (messages.length-fail_cnt) + ' success');
63+
64+
callback(null, `${messages.length - fail_cnt} success`);
6065
}
6166
});
6267
})(i);
6368
}
64-
6569
} else {
70+
6671
callback(null, 'success');
6772
}
68-
});
73+
} catch (error) {
74+
callback(error);
75+
}
6976
};
7077

7178
exports.handler = function (event, context, callback) {
72-
73-
var env = Object.assign({}, process.env);
74-
env['is_worker'] = event.is_worker || 0;
79+
const env = Object.assign({}, process.env);
80+
env.is_worker = event.is_worker || 0;
7581
exports.consumeMessages(env, context, callback);
76-
};
77-
82+
};
Binary file not shown.

cloudwatchlogs-with-dlq/cloudwatchlogs_lambda.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,25 @@ var url = require('url');
1919
var vpcutils = require('./vpcutils');
2020
var SumoLogsClient = require('./sumo-dlq-function-utils').SumoLogsClient;
2121
var Utils = require('./sumo-dlq-function-utils').Utils;
22-
const AWS = require('aws-sdk');
23-
const ssm = new AWS.SSM();
22+
23+
const { SSMClient, GetParameterCommand } = require("@aws-sdk/client-ssm");
2424

2525
exports.getEndpointURL = async function() {
26-
console.log('Getting SUMO_ENDPOINT from AWS SSM Parameter Store');
27-
return new Promise((resolve, reject) => {
28-
ssm.getParameter(
29-
{
30-
Name: 'SUMO_ENDPOINT',
31-
WithDecryption: true
32-
},
33-
(err, data) => {
34-
if (err) {
35-
console.log(err, err.stack);
36-
reject(new Error('Unable to get EndpointURL from SSM: ' + err));
37-
} else {
38-
// console.log(data);
39-
resolve(data.Parameter.Value);
40-
}
41-
}
42-
);
43-
});
44-
}
26+
console.log('Getting SUMO_ENDPOINT from AWS SSM Parameter Store');
27+
const ssmClient = new SSMClient();
28+
try {
29+
const data = await ssmClient.send(
30+
new GetParameterCommand({
31+
Name: 'SUMO_ENDPOINT',
32+
WithDecryption: true
33+
})
34+
);
35+
return data.Parameter.Value;
36+
} catch (error) {
37+
console.error('Unable to get EndpointURL from SSM:', error);
38+
throw new Error('Unable to get EndpointURL from SSM: ' + error);
39+
}
40+
}
4541

4642
function createRecords(config, events, awslogsData) {
4743
var records = [];
@@ -210,4 +206,4 @@ exports.handler = function (event, context, callback) {
210206

211207
exports.processLogs(process.env, event.awslogs.data, callback);
212208

213-
};
209+
};

0 commit comments

Comments
 (0)