- Newest
- Most votes
- Most comments
As mentioned in the NodeJS API error documentation: [+] https://nodejs.org/api/errors.html ENOENT (No such file or directory): Commonly raised by fs operations to indicate that a component of the specified pathname does not exist. No entity (file or directory) could be found by the given path.
Taking a deeper look at the error, it seems that the error originates from fs readFileSync() function.
I am able to replicate this error using fs :
const path = require('path'); const fs = require('fs'); exports.handler = async (event) => { return fs.readFileSync('/keys/config.json') };
Assuming that the function has the below directory structure:
- Function-name
- index.js
- keys/config.json
The path specified is /key/config.json which will not work as the actual path of the file in the above directory structure is /var/task/key/config.json in lambda execution environment. We need to provide 'keys/config.json' as shown in the link below:
const path = require('path'); const fs = require('fs'); exports.handler = async (event) => { return fs.readFileSync('keys/config.json')}; // or /var/task/keys/config.json
My config.json file contains text 'ABC' and the function returns '65 66 67' (ASCII values) as expected.
Relevant content
- asked 2 years ago
- asked 6 years ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
I am not getting above one. Since the KeyFIle prop of GoogleAuth requires filePath to json file. How can I reference the same? That prop is not required content instead file Path. Though I reference the correct file path, that was not recognized by the Lambda environment.