I have created a Lambda function (Node.js 12.x) in AWS so SNS messages are pushed to Slack from our ETL tool Matillion.
console.log('Loading function');
const https = require('https');
const url = require('url');
const slack_url = 'https://hooks.slack.com/services/T1MJBHQ95/B01DQ60NUR2/....';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = { 'Content-Type': 'application/json' };
exports.handler = function (event, context) {
(event.Records || []).forEach(function (rec) {
if (rec.Sns) {
var req = https.request(slack_req_opts, function (res) {
if (res.statusCode === 200) {
context.succeed('sns posted to slack');
}
else {
context.fail('status code: ' + res.statusCode);
}
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
context.fail(e.message);
});
req.write(JSON.stringify({ text: `${rec.Sns.Message}` }));
req.end();
}
});
};
The function will fail with a missing ) after argument list syntax error. I run it thru a linter in Sublime and it throws an error on require and exports being undefined.
My research shows several challenges:
- I may need a file called eslint.rc but I am unclear why I need to put in.
- The use of "require" and "exports" appears deprecated.
Can someone please give me pointers how what to focus on to resolve this? Thank you.
Error require is not defined. (no-undef)andexports is not defined. (no-undef)are the errors I get when I run my code locally. That's why I assumed both functions are server-based.