【问题标题】:AWS Lambda Cannot find module 'index'AWS Lambda 找不到模块“索引”
【发布时间】:2021-09-13 21:06:00
【问题描述】:

我使用的是非常简单的设置,但我使用的是打字稿。我目前将我的打字稿编译到 /dist 目录中。

尝试使用 Webstorm 进行调试时,我发现处理程序没有问题:

但是当我运行它时,我得到以下错误:

2021-07-01T19:48:54.216Z 未定义错误未捕获异常 {"errorType":"Runtime.ImportModuleError","errorMessage":"错误: 找不到模块“索引”\n需要堆栈:\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","stack":["Runtime.ImportModuleError: 错误: 找不到模块 'index'","需要堆栈:","- /var/runtime/UserFunction.js","- /var/runtime/index.js"," 在 _loadUserApp (/var/runtime/UserFunction.js:100:13)"," 在 Object.load (/var/runtime/UserFunction.js:140:17)"," 在 目的。 (/var/runtime/index.js:43:30)"," 在 Module._compile (internal/modules/cjs/loader.js:1060:14)"," 在 Object..js (internal/modules/cjs/loader.js:1092:10)"," 在 Module.load (internal/modules/cjs/loader.js:928:32)"," 在 Function._load (internal/modules/cjs/loader.js:769:14)"," 在 Function.executeUserEntryPoint [作为 runMain] (内部/模块/run_main.js:72:12)"," 在 内部/main/run_main_module.js:17:47"]}

我也将 template.yaml 复制到 dist 目录中。 template.yaml 文件如下所示:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  my-lambda-function

  
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: .
      Handler: index.handler
      Runtime: nodejs14.x

非常基础。

./dist目录结构如下:

./dist
  |
  |- /node_modules
  |- index.js
  |- package.json
  |- template.yaml

【问题讨论】:

    标签: node.js typescript aws-lambda


    【解决方案1】:

    我最终将 WebStorm 调试配置切换为模板:

    我还在我的资源下的 template.yaml 中更新了这个:

    Resources:
      BulkImageLambdaFunction:
        Type: AWS::Serverless::Function
        Properties:
          CodeUri: ./dist
          Handler: index.handler
          Runtime: nodejs14.x
    

    此后,调试器运行正常。

    【讨论】:

      猜你喜欢
      • 2015-08-21
      • 1970-01-01
      • 2021-12-16
      • 2021-11-20
      • 2021-04-20
      • 2016-11-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-16
      相关资源
      最近更新 更多