[英]how do I run my telegraf bot on AWS Lambda
So I have this simple telegraf bot that works when I run it locally with node.所以我有这个简单的 telegraf 机器人,当我用节点在本地运行它时它可以工作。 I also managed to create some simple Lambda functions, but I can't figure out how to actually run the bot on the lambda.我还设法创建了一些简单的 Lambda 函数,但我不知道如何在 lambda 上实际运行机器人。 I tried this:我试过这个:
const { Telegraf } = require("telegraf");
exports.handler = async (event) => {
const bot = new Telegraf(<token goes here>);
bot.start((ctx) => ctx.reply("👍"));
bot.launch();
const response = {
statusCode: 200,
body: JSON.stringify('OK'),
};
return response;
};
But I'm sure this is not the way it is supposed to be implemented但我确定这不是应该实施的方式
I'm not that familiar with telegraf, however, if you must have it on Lambda function, you can add its package as Lambda layer.我对 telegraf 不是很熟悉,但是,如果你必须在 Lambda 函数上使用它,你可以将它的包添加为 Lambda 层。
See what Lambda layer and how to leverage it in the following aws docs .在以下 aws 文档中查看什么 Lambda 层以及如何利用它。
By the way, like everyone mentioned above in the comment section, Lambda has limited resource such 15 minutes execution time as well as Lambda is one of expensive AWS resources compare to EC2.顺便说一句,就像上面评论部分提到的每个人一样,Lambda 的资源有限,例如 15 分钟的执行时间,而且与 EC2 相比,Lambda 是昂贵的 AWS 资源之一。 Also if telegraf is a heavy package or its process takes longer than 15 minutes, the Lambda function will be failed and you will have to configure DLQ.此外,如果 telegraf 是一个沉重的包或它的过程需要超过 15 分钟,Lambda 功能将失败,您将必须配置 DLQ。
Maybe for these reasons, people don't recommend you to run telegraf on Lambda function.也许出于这些原因,人们不建议您在 Lambda 函数上运行 telegraf。
Idealy, you can find more architecture using Fargate or EC2.理想情况下,您可以找到更多使用 Fargate 或 EC2 的架构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.