简体   繁体   English

如何在 AWS Lambda 上运行我的 telegraf 机器人

[英]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.

相关问题 如何使用 Lambda 批量加载 AWS Neptune? - How do i Bulk Load AWS Neptune using a Lambda? 如何使用 lerna 将 monorepo 代码部署到 AWS Lambda? - How do I deploy monorepo code to AWS Lambda using lerna? 如何使用 AWS CDK 中的 InvokeLambda 将 JSON 传递给 AWS StepFunction 中的 lambda - How do I pass JSON to lambda in AWS StepFunction using InvokeLambda in AWS CDK 我可以通过 python 在 aws lambda 中运行 Maven 依赖项吗? - Can i run maven dependency in aws lambda via python? 如何在 AWS Lambda 中执行 Shellscript。 我想将我的脚本作为无服务器代码 - How to execute Shellscript in AWS Lambda . I would like to my script as serverless code 如何使用 GET 请求将参数传递给 AWS Lambda 函数? - How do I pass arguments to AWS Lambda functions using GET requests? 如何使用 `experimental-edge` runtime 在 AWS lambda 中运行 nextjs - How to run nextjs in AWS lambda with `experimental-edge` runtime 如何使用 AWS CLI 创建 AWS Lambda 函数? - How can I create an AWS Lambda function using the AWS CLI? 如何使用 API 网关集成访问 Node js AWS Lambda 中的 POST 参数? - How do I access a POST parameter in Node js AWS Lambda with API Gateway integration? 当我的 aws lambda 函数执行时如何选择弹性 IP - How to choose Elastic IP when my aws lambda function execute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM