Lambda函数失败,无法导入模块“索引" [英] Lambda function failing with Unable to import module 'index'

查看:148
本文介绍了Lambda函数失败,无法导入模块“索引"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:

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/node_modules/slack-incoming-webhook/lib/index.js:3:19)
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)

从外观上看,我的代码不是问题,这是松弛传入的Webhook节点模块的问题,但是令人讨厌的代码是这一行,看起来很正常.

By the looks of this my code isn't the problem it's a problem with the slack-incoming-webhook node-module however the piece of offending code is this line which looks completely normal.

var SlackClient = require('./client');

我现在尝试了4种不同的程序包(请求,http,node-webhooks和现在的slack-incoming-webhooks),它们都因节点模块中的代码而失败.我非常困惑,因为我可以使代码在我自己的计算机和Amazon Linux AMI EC2实例(运行相同节点版本)上运行

I have tried 4 different packages now (request, http, node-webhooks and now slack-incoming-webhooks) and they are all failing with code in node modules. I am thoroughly confused as I can get the code to work on my own computer and on an Amazon Linux AMI EC2 Instance (running same node version)

使用aws-cli将所有代码压缩并发送到lambda,并且之前我在lambda上部署了node.js代码,没有任何问题(alexa技能).

All the code is zipped and sent to lambda using the aws-cli and I have deployed node.js code on lambda before without any problems (alexa skill).

我尝试在ec2实例上安装npm,尝试了几种不同的软件包,得出的结论是lambda中肯定存在某种配置错误,但我找不到.有人可以指出我正确的方向...

I have tried npm install on the ec2 instance, I have tried several different packages and I have come to the conclusion there must be some sort of configuration wrong in lambda but I can't find what. Could someone point me in the right direction...

这是我的代码,如果有人好奇并且lambda触发器是aws物联网按钮.

Here is my code if anyone is curious also the lambda trigger is an aws iot button.

const slack = require('slack-incoming-webhook');
const send = slack({
    url: 'https://hooks.slack.com/....'
});

exports.handler = function ()
{
    send(process.env.company + ' has pushed their panic button! PANIC! PANIC! PANIC!');
};

推荐答案

这是我在许多帖子中看到的常见问题.在大多数情况下,这是将文件压缩成问题的方式.不必压缩文件夹,您必须选择所有文件并按如下所示对其进行压缩,

This is common issue I have seen in many posts. Most of the cases it is the way zipping the files making the problem. Instead of zipping the folder you have to select all files and zip it like below,

这篇关于Lambda函数失败,无法导入模块“索引"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆