-
-
Save Xanaxiel/38e23794223ef9cddf772562f5a24a70 to your computer and use it in GitHub Desktop.
Revisions
-
m2wasabi revised this gist
Aug 11, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ Post SNS Message to Discord Webhook | Platform | Node.js 14 | | handler | index.handler | ## Environment Variables | Key | Description | | --- | --- | -
m2wasabi created this gist
Aug 10, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ # AWS SNS to Discord Webhook Post SNS Message to Discord Webhook ## Lambda Preferences | Key | Value | | --- | --- | | Platform | Node.js 14 | | handler | index.handler | ## Environment Variavles | Key | Description | | --- | --- | | WEBHOOK_DISCORD | Discord Webhook URL | This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ const webhookUrl = process.env.WEBHOOK_DISCORD; const https = require('https'); const url = new URL(webhookUrl); exports.handler = function(event, context, callback) { send_message(event); }; function send_message(events){ const body = create_message(events); const options = { host: url.host, path: url.pathname, port: url.port, method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(JSON.stringify(body)) }, }; let req = https.request(options, (res) => { res.on('error', (e) => { console.log('problem with request: ' + e.message); }); }); req.write(JSON.stringify(body)); req.end(); } function create_message(events){ const sns = events.Records[0].Sns; const data = { 'embeds': [ { 'title': 'AWS Notification: ' + sns.Subject, 'description': sns.Message, 'color': 0xFF0000, 'timestamp': sns.Timestamp, } ] }; return data; }