slack通知用モジュール新規作成
This commit is contained in:
parent
3558564def
commit
d4a978885e
37
lambda/mbj-newdwh2021-staging-NoticeToSlack/index.js
Normal file
37
lambda/mbj-newdwh2021-staging-NoticeToSlack/index.js
Normal 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}.`
|
||||
});
|
||||
})
|
||||
|
||||
};
|
||||
15
lambda/mbj-newdwh2021-staging-NoticeToSlack/package.json
Normal file
15
lambda/mbj-newdwh2021-staging-NoticeToSlack/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user