ログ検知用モジュール新規追加
This commit is contained in:
parent
de2dbf2932
commit
296be89c53
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
lambda/mbj-newdwh2021-staging-NoticeToSlack/package-lock.json
|
||||
lambda/mbj-newdwh2021-staging-NoticeToSlack/node_modules/*
|
||||
lambda/mbj-newdwh2021-staging-NoticeToSlack/node_modules/*
|
||||
lambda/mbj-newdwh2021-staging-PublishFromLog/package-lock.json
|
||||
lambda/mbj-newdwh2021-staging-PublishFromLog/node_modules/*
|
||||
30
lambda/mbj-newdwh2021-staging-PublishFromLog/index.js
Normal file
30
lambda/mbj-newdwh2021-staging-PublishFromLog/index.js
Normal file
@ -0,0 +1,30 @@
|
||||
const zlib = require("zlib");
|
||||
const aws = require("aws-sdk");
|
||||
const sns = new aws.SNS({
|
||||
apiVersion: "2010-03-31",
|
||||
region: 'ap-northeast-1'
|
||||
});
|
||||
|
||||
exports.handler = function(input, context) {
|
||||
var payload = new Buffer.from(input.awslogs.data, 'base64');
|
||||
zlib.gunzip(payload, function(e, result) {
|
||||
if (e) {
|
||||
context.fail(e);
|
||||
} else {
|
||||
result = JSON.parse(result.toString('UTF-8'));
|
||||
const publishMessage = {
|
||||
Subject: `Application Error(or Warning) in ${result.logGroup}/${result.logStream}`,
|
||||
Message: result.logEvents.map((l) => l.message).join('\n'),
|
||||
TopicArn: process.env.topicArn
|
||||
};
|
||||
console.log(publishMessage);
|
||||
|
||||
sns.publish(publishMessage, (err, data) => {
|
||||
console.log(err, data);
|
||||
if(err){
|
||||
context.fail('fail');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
Binary file not shown.
15
lambda/mbj-newdwh2021-staging-PublishFromLog/package.json
Normal file
15
lambda/mbj-newdwh2021-staging-PublishFromLog/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "mbj-newdwh2021-staging-publishfromlog",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"aws-sdk": "^2.1011.0",
|
||||
"zlib": "^1.0.5"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user