I try to create a lambda function to post a message in Slack.
const { WebClient } = require('@slack/client');
const token = '...';
const web = new WebClient(token);
const channel = '#...';
exports.handler = (event) => {
console.log('First');
web.chat.postMessage({
channel: channel,
username: '...',
icon_emoji: '...',
text: 'Hello world'
})
.then(() => {
console.log('Ok');
return {
statusCode: 200
};
})
.catch((error) => {
console.log('Error', error);
return {
statusCode: 500,
body: error
};
});
console.log('Finish');
};
My question : how I can do to return the return in my then
and catch
function ?
Actually, lambda return null
. (Ok, because I haven't return in my main function). So If my function failed, Lambda return still an answer (200).
Maybe I don't use correctly Lambda and Promise. Moreover I don'y really understand the keyword await
before (event) => {
. I'm forced to remove it otherwise my function does not work.