【发布时间】:2020-07-10 11:22:40
【问题描述】:
我有一个 Amplify 项目,我想在其中使用 lambda 层。层和 lambda 已使用 Amplify CLI 进行配置。
Lambda 层命名为“common”。该文件是./amplify/backend/function/common/opt/param.js。它导出一个函数:
const getValue = async (name) => {
...
}
module.exports = getValue;
在我的 lambda 函数中,我想使用上面的辅助函数。但是,我不知道如何导入它。我试过了:
const getValue = require('param');
const getValue = require('./param');
const getValue = require('/opt/param');
const getValue = require('./opt/param');
但他们都失败了,错误如下:
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module '/opt/param'
还请注意,我在推送层后更新了 lambda,并将其连接到最新的层版本。所以代码应该可用于 lambda。
【问题讨论】:
标签: javascript amazon-web-services aws-lambda aws-lambda-layers