slack通知用モジュール新規作成

This commit is contained in:
x.azuma.m@nds-tyo.co.jp 2021-10-19 16:53:57 +09:00
parent 3558564def
commit d4a978885e
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,37 @@
"use-strict";
const request = require("request-promise");
exports.handler = (event, context, callback) => {
const attaches = event.Records.map(evt => {
return {
"fallback":`Notification from mbj-newdwh2021 AWS: ${evt.EventSubscriptionArn}`,
"pretext":`Notification from mbj-newdwh2021 AWS: ${evt.EventSubscriptionArn}`,
"color":"#0000D0",
"fields":[
{
"title": `${evt.Sns.Subject}`,
"value": `${evt.Sns.Timestamp}: ${evt.Sns.Message} (MessageId: ${evt.Sns.MessageId})`,
"short": false
}
]
};
});
request({
method: "POST",
url: process.env.webhookurl,
body: {
attachments: attaches
},
json: true
}).then((body => {
callback(null, `Request succeed. ${body}`);
})).catch((err) => {
callback("failed to request to slack.", {
result: "ERROR",
event: event,
cause: `request failed. ${err}.`
});
})
};

View File

@ -0,0 +1,15 @@
{
"name": "mbj-newdwh2021-staging-noticetoslack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"request": "^2.88.2",
"request-promise": "^4.2.6"
}
}