Lambda函数失败,无法导入模块“索引"

编程入门 行业动态 更新时间:2024-10-27 12:29:41
本文介绍了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: 'hooks.slack/....' }); exports.handler = function () { send(process.envpany + ' 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函数失败,无法导入模块“索引"

本文发布于:2023-11-28 09:23:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   模块   索引   Lambda   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!