AWS Lambda Node.js 6.10:“errorMessage”:“无法找到模块'cfn-response'”,

时间:2018-02-21 16:30:09

标签: node.js amazon-web-services aws-lambda

我正在尝试在Nodejs 6.10中部署lambda函数,我收到此错误:

Response: 
{
    "errorMessage": "Cannot find module 'cfn-response'",
    "errorType": "Error", 
    "stackTrace": [
       "Module.require (module.js:497:17)",
       "require (internal/module.js:20:19)", 
       "Object. (/var/task/index.js:2:20)", 
       "Module._compile (module.js:570:32)", 
       "Object.Module._extensions..js (module.js:579:10)",
       "Module.load (module.js:487:32)", 
       "tryModuleLoad (module.js:446:12)",
       "Function.Module._load (module.js:438:3)" 
    ]
}

Function Logs:

START RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8 Version: $LATEST

Unable to import module 'index': Error
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/var/task/index.js:2:20)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
END RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8
REPORT RequestId: d1123bc9-1722-11e8-84a2-c9cba9c66de8  Duration: 87.34 ms  Billed Duration: 100 ms     Memory Size: 128 MB Max Memory Used: 32 MB  

我正在使用Node.js 6.10版本进行此方法并进行内联代码编辑。

我正在尝试执行的代码:

var response = require('cfn-response');
  exports.handler = function(event, context) {
    var input = parseInt(event.ResourceProperties.Input);
    var responseData = {Value: input * 5};
    response.send(event, context, response.SUCCESS, responseData);
  };

任何线索?

1 个答案:

答案 0 :(得分:0)

主要是因为压缩文件导致问题的方式。不必压缩根文件夹,而是必须选择所有文件并将其压缩如下,

请上传所有文件和子文件夹,如下所示。请在zip中包含node_modules文件夹。

enter image description here