fs.readFileSync cannot find file when deploying with lambda

kar*_*eem 2 json amazon-web-services node.js aws-lambda serverless-framework

In my code I am calling a query from my lambda function

let featured_json_data = JSON.parse(fs.readFileSync('data/jsons/featured.json'))
Run Code Online (Sandbox Code Playgroud)

This works locally because my featured.json is in the directory that I am reading from. However when I deploy with serverless, the zip it generates doesn't have those files, I get a

ENOENT: no such file directory, open...

I tried packaging by adding

package: 
include: 
 - data/jsons/featured.json
Run Code Online (Sandbox Code Playgroud)

but it just doesn't work. The only way I get this to work is manually adding the json file and then change my complied handler.js code to read from the json file in the root directory.

In this screenshot I have to add the jsons then manually upload it again and in the compiled handler.js code change the directory to exclude the data/jsons

在此处输入图片说明

I want to actually handle this in my servereless.yml

das*_*mug 5

您可以使用require().

const featured_json_data = require('./featured.json')
Run Code Online (Sandbox Code Playgroud)

或者更好的是,将您的 JSON 转换为 JS!