最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

AWS Lambda错误:“找不到模块' vartaskindex'”

运维笔记admin11浏览0评论

AWS Lambda错误:“找不到模块'/ var / task / index'”

AWS Lambda错误:“找不到模块'/ var / task / index'”

Node.js Alexa任务问题

我目前正在通过AWS Lambda编写Node.js Alexa任务,我一直在尝试编写一个函数来接收来自OpenWeather API的信息并将其解析为一个名为weather的变量。相关代码如下:

var request = require('request');
var weather = "";
function isBadWeather(location) {
      var endpoint = ".5/weather?q=" + location + "&APPID=205283d9c9211b776d3580d5de5d6338";
      var body = "";
      request(endpoint, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                  body = JSON.parse(body);
                  weather = body.weather[0].id;
            }
      });
}

function testWeather()
{
      setTimeout(function() {
      if (weather >= 200 && weather < 800)
            weather = true;
      else
            weather = false;
      console.log(weather);
      generateResponse(buildSpeechletResponse(weather, true), {});
      }, 500);
}

我在Cloud9和其他IDE中无数次运行这个片段,它似乎运行得很完美。但是,当我将其压缩到一个包并将其上传到AWS Lambda时,我收到以下错误:

{
    "errorMessage": "Cannot find module '/var/task/index'",
    "errorType": "Error",
    "stackTrace": [
        "Function.Module._load (module.js:276:25)",
        "Module.require (module.js:353:17)",
        "require (internal/module.js:12:17)"
    ]
}

我搜索了无数文章,并安装了模块-j,请求和许多其他Node模块,这些模块应该使这个代码运行,但似乎没有什么能解决这个问题。这是我的目录,以防万一:

- planyr.zip
   - index.js
   - node_modules
   - package.json

有谁知道这个问题是什么?非常感谢你提前。

回答如下:

固定它!我的问题是我试图在Finder中使用Mac的内置压缩功能压缩文件。

如果您是Mac用户,就像我一样,当您位于项目的根目录(包含index.jsnode_modules等文件的文件夹)时,应在终端中运行以下脚本。

zip -r ../yourfilename.zip *

对于Windows:

Compress-Archive -LiteralPath node_modules, index.js -DestinationPath yourfilename.zip
发布评论

评论列表(0)

  1. 暂无评论