I have the following handler for my AWS Lambda function. I don't want to or need to wait for Promise.all resolve or reject. Because, I am not interested about its result. My purpose is to just send those requests and finish.
The problem is that if I remove the await keyword (pointed with an arrow), the requests are not firing up. But, if I put the await keyword, the Lambda function needs to run and be charged for 3-5 seconds, and it is not cost effective for me.
Could you explain what I am doing wrong? Why the requests are not being sent without the await keyword?
module.exports.handler = async (event) => {
try {
const urls = [/*some API urls*/];
--> await Promise.all(urls.map((url) => {
return axios.post(url, { email })
.catch((error) => {
console.log(error);
});
}));
return {
statusCode: 200,
body: JSON.stringify({ message: 'OK' }),
headers: {
'Content-Type': 'application/json',
},
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ message: 'INTERNAL_ERROR' }),
headers: {
'Content-Type': 'application/json',
}
}
}
};