How can I wait for the forEach loop to finish before the return statement is executed in aws lambda?
module.exports.shipments = async (event) => {
const axios = require("axios");
let data = JSON.parse(event.body);
let url = data.apiURL + "/api/1.1/wf/bulkshipments/initialize";
let patchURL = data.apiURL + "/api/1.1/obj/company/" + data.companyID;
data.shipments.forEach((item, index, array) => {
axios.post(url,{
batchID: data.batchID,
companyID: data.companyID,
shipment: item})
});
return {
statusCode: 200,
body: JSON.stringify({
message: 'Created successfully!',
totalShipments: data.shipments.length,
}, null, 2),
};
};