0

I'm using ExcelJS to read an Excel file ,the code is working fine in the local machine and even when I use the serverless invoke local command, but when deployed on lambda it is not working. The error I'm getting could be found on the attached image. Below is my code please help:

async function readExcel(fileUrl) {
      try {
        console.log(fileUrl);
        const response = await axios.get(fileUrl, { responseType: 'arraybuffer' });
        const workbook = new ExcelJS.Workbook();
        await workbook.xlsx.load(response.data);
        const data = [];

    const worksheet = workbook.getWorksheet(1);

    worksheet.eachRow((row, rowNumber) => {
      // Assuming each row contains data in a specific format (adjust as needed)
      const rowData = {
        LeadName: row.getCell(1).value, 
        MobileNumber: row.getCell(2).value, 
        Email:row.getCell(3).text,
        VehicleRegistrationNumber: row.getCell(4).value,
        City:row.getCell(5).value,
        City_Id: row.getCell(6).value,
        Comments: row.getCell(7).value,
        VehicleModel: row.getCell(8).value,
        AgeGroup:row.getCell(9).value,
        Gender:row.getCell(10).value,
        Destination:row.getCell(11).value,
        Medium:row.getCell(12).value,
        Campaign:row.getCell(13).value,
        LeadSource :row.getCell(14).value
      };
      data.push(rowData);
    });
    data.shift();
    return data;
  } catch (error) {
    console.error('Error reading Excel file:', error);
    throw error;
  }
}

I tried to change the code logged data it is there data is coming in response.data I'm expecting the code to run and return the data array.

2
  • Can you share the code for your HTTP handler? Commented May 16, 2024 at 2:18
  • This is a api , can you be more specific, I'm using axios to fetch the s3 url where I'm storing the excel. Commented May 16, 2024 at 5:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.