Encountering an issue with the "map" section when attempting to run it - receiving an error message stating "Cannot read property 'map' of undefined"
The customers
constant is defined above, so I'm unsure where the undefined value is originating from. Do we need to explicitly declare the map function somewhere?
const AWS = require('aws-sdk'),
ses = new AWS.SES(),
fetch = require('node-fetch');
exports.handler = async (event) => {
console.log(event.customer_id);
const customers = await getCustomers();
customers.map(async customer => await sendEmailToCustomer(customer));
const customersEmailsPromises = customers.map(async customer => await sendEmailToCustomer(customer));
}
async function getCustomers() {
try {
const resp = await fetch('https://3objects.netlify.com/3objects.json');
const json = await resp.json();
return json;
}
catch(e) {
throw e;
}
}
const sendEmailToCustomer = (customer) => new Promise((resolve, reject) => {
ses.sendEmail({
Destination:
{ ToAddresses: [customer.email] },
Message:
{
Body: { Text: { Data: `Your contact option is ${customer.customer_id}` } },
Subject: { Data: "Your Contact Preference" }
},
Source: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5320323f362013362b323e233f367d-3d303c3e">[email protected]</a>"
}, (error, result => {
if (error) return reject(error);
resolve(result);
console.log(result);
})
);
})