Home > front end >  How to resolve ENOENT: no such file or directory, open '/index.js' issue occurred in Lambd
How to resolve ENOENT: no such file or directory, open '/index.js' issue occurred in Lambd

Time:08-03

I have an API written in node.js which was working fine with async calls then suddenly throwing below error after a recent code deployment.

2022-08-01T12:11:41.332Z    d759bb19-f1d3-4fd7-8c5f-852fb41afe6a    ERROR   Unhandled Promise Rejection 
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "Error: ENOENT: no such file or directory, open '/index.js'",
"reason": {
    "errorType": "Error",
    "errorMessage": "ENOENT: no such file or directory, open '/index.js'",
    "code": "ENOENT",
    "errno": -2,
    "syscall": "open",
    "path": "/index.js",
    "stack": [
        "Error: ENOENT: no such file or directory, open '/index.js'"
    ]
},
"promise": {},
"stack": [
    "Runtime.UnhandledPromiseRejection: Error: ENOENT: no such file or directory, open '/index.js'",
    "    at process.<anonymous> (/var/runtime/index.js:35:15)",
    "    at process.emit (events.js:314:20)",
    "    at process.emit (/var/task/src/api/ecmAuthApi/webpack:/Project/node_modules/source-map-support/source-map-support.js:516:1)",
    "    at processPromiseRejections (internal/process/promises.js:209:33)",
    "    at processTicksAndRejections (internal/process/task_queues.js:98:32)"
]
}

And below is my relevant source code

// service.js
const getUserPermissions = async (token, correlationId) => {
const testUserBucketParams = {
  Bucket: authConstants.META_DATA_TEMPLATE_S3_BUCKET_NAME,
  Key: authConstants.TEST_USERS,
};
try {
const testUsersFile = await s3Connector
  .getData(testUserBucketParams, { awsRequestId: correlationId });
const testUsersMapping = getJson(testUsersFile);
const payloadData = await Promise.resolve(
  validateToken(
    token, authConstants.LIBERTY_USER_POOL_JWK_URL, testUsersMapping, correlationId,
  ),
);
return await Promise.resolve(getDataFromDB(payloadData, correlationId));
} catch (error) {
  return 1;
}

and the Util function

// utils
import AWS from 'aws-sdk';
import { validateS3Fetch } from '../util/commonUtil';
const s3 = new AWS.S3();
const getData = async (params, context) => {
  const file = await s3.getObject(params).promise(); // the error occurs here
  validateS3Fetch(file, params, context);
  return file.Body.toString('utf-8');
};

export default { getData };

FYI, this implementation was working perfect until i redeploy the code again today. And there were no changes in package.json too. But it works fine locally.

What am I missing here? Is it an issue with AWS lambda?

CodePudding user response:

There is nothing wrong in the implementation. But my code was attached with datadog and it's API key was expired. After updating the key, it's working fine both locally and remotely :)

  • Related