AWS 尝试在 Lambda 函数之间建立连接

AWS attempted connection between Lambda functions

提问人:Santiago Blanca 提问时间:11/16/2023 最后编辑:John RotensteinSantiago Blanca 更新时间:11/17/2023 访问量:30

问:

我正在尝试为一个项目连接 AWS 中的 Lambda 函数,它们都位于同一区域并具有相同的节点版本,这是我使用的脚本,当我尝试时,它不起作用。

这是我使用的脚本:

const { AWS } = require("@aws-sdk/client-s3");
AWS.config.region = "us-west-2";
const lambda = new AWS.Lambda();

const invokeLambda = async (event, SEARCH) => {
  return await new Promise((resolve, reject) => {
    const params = {
      InvocationType: "Event",
      FunctionName: SEARCH,
      Payload: JSON.stringify(event)
    };
    lambda.invoke(params, (err, data) => {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });
};

module.exports = invokeLambda;

这是错误:

{
  "errorType": "ReferenceError",
  "errorMessage": "require is not defined in ES module scope, you can use import instead",
  "trace": [
    "ReferenceError: require is not defined in ES module scope, you can use import instead",
    "    at file:///var/task/index.mjs:1:17",
    "    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)"
  ]
}

报名结果

2023-11-16T13:41:57.558Z    undefined   ERROR   Uncaught Exception  {"errorType":"ReferenceError","errorMessage":"require is not defined in ES module scope, you can use import instead","stack":["ReferenceError: require is not defined in ES module scope, you can use import instead","    at file:///var/task/index.mjs:1:13","    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)"]}
INIT_REPORT Init Duration: 187.15 ms    Phase: init Status: error   Error Type: Runtime.ExitError
2023-11-16T13:41:59.227Z    undefined   ERROR   Uncaught Exception  {"errorType":"ReferenceError","errorMessage":"require is not defined in ES module scope, you can use import instead","stack":["ReferenceError: require is not defined in ES module scope, you can use import instead","    at file:///var/task/index.mjs:1:13","    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)"]}
INIT_REPORT Init Duration: 1893.92 ms   Phase: invoke   Status: error   Error Type: Runtime.ExitError
START RequestId: 37d064b6-dfd3-4480-9bd4-78c25b15decb Version: $LATEST
Unknown application error occurred
Runtime.Unknown
END RequestId: 37d064b6-dfd3-4480-9bd4-78c25b15decb
REPORT RequestId: 37d064b6-dfd3-4480-9bd4-78c25b15decb  Duration: 1895.28 ms    Billed Duration: 1896 ms    Memory Size: 128 MB Max Memory Used: 17 MB  

亚马逊网络服务 AWS-Lambda

评论

1赞 Mark B 11/16/2023
对于您使用的 NodeJS 版本,您需要使用 而不是 .importrequire
0赞 jarmod 11/17/2023
无需创建承诺或使用回调来手动解析/拒绝事物。您的整个 Lambda 函数可以写成:const params = {...}; return lambda.invoke(params).promise();

答: 暂无答案