38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
"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}.`
|
|
});
|
|
})
|
|
|
|
};
|