AWS Lambda fs.readfile问题 [英] AWS Lambda fs.readfile issue

查看:105
本文介绍了AWS Lambda fs.readfile问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些文件打包在我需要的lambda包中.我使用了一些浮动示例,以使它几乎可以正常工作.

I'm packing some files in my lambda package that I need. I've used some example floating around to nearly get it working.

我可以验证文件的路径了

I'm able to verify the path of a file OK

const deviceCert = path.resolve(certType + "-deviceCert.key");

注销到

"message": "Resolved path to TEST-deviceCert.key: /var/task/TEST-deviceCert.key"

当我尝试使用读取文件时

when I attempt to read the file using

fs.readFile(deviceCert, (err, data) => {

    if (err) {

        log.error(`Verify deviceCert failure: ${err}`);
        responseBody = Helper.buildCORSResponse(502, JSON.stringify({ message: "Unable to locate file required" }));

        return callback(null, responseBody);

    }

});

我收到以下错误

Error: ENOENT: no such file or directory, open '/var/task/TEST-deviceCert.key'"

如果我可以验证路径,那我为什么不能读取它?

If I can verify the path then why cant I read it?

任何想法?

推荐答案

从node.js复制 path.resolve() API文档:

Copied from the node.js path.resolve() API documentation:

path.resolve()方法将一系列路径或路径段解析为绝对路径.

The path.resolve() method resolves a sequence of paths or path segments into an absolute path.

换句话说,resolve将一串字符串连接成一个字符串,格式为绝对路径.但是,它不会检查此位置是否有文件.您可以使用 fs.stat()

In other words, resolve concatenates a sequence of strings into one string, formatted as an absolute path. However, it does not check whether or not there is a file at this location. You can use either fs.stat() or fs.access() to verify the presence and access of the file.

这篇关于AWS Lambda fs.readfile问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆