SQS 触发的 AWS Lambda 增加 SQS 请求计数 [英] AWS Lambda Triggered by SQS increases SQS request count

查看:44
本文介绍了SQS 触发的 AWS Lambda 增加 SQS 请求计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 SQS 触发的 AWS Lambda 函数.此函数每天触发大约 100 次,但对 SQS 队列的请求计数每天大约为 20.000 次.我不明白为什么向 SQS 提出的请求数量太高.我的期望是向 SQS 发出的请求数量应该与 Lambda 调用相同.

I have a AWS Lambda function which is triggered by SQS. This function is triggered approximately 100 times daily, but request count to the SQS queue is approximately 20.000 times daily. I don't understand why the number of requests made to the SQS is too high. My expectation is that the number of requests made to the SQS should be same with the Lambda invocation.

我的帐户中只有一个 Lambda 函数和一个 SQS 队列.

I have only one Lambda function and one SQS queue in my account.

可以和SQS队列的轮询有关吗?我试图从队列配置中更改 SQS 的轮询间隔,但没有任何改变.另一种可能性是从 Lambda 函数配置更改轮询间隔.但是,我找不到任何相关参数.

Can be related with polling of SQS queue? I tried to change the polling interval of SQS from the queue configuration but nothing changed. Another possibility is to change polling interval from Lambda function configuration. However, I cannot find any related parameter.

简而言之,我想减少 SQS 请求的数量,在使用 SQS 调用 Lmabda 函数时如何做到这一点?

Briefy, I want to reduce number of SQS request, how can i do that while invoking Lmabda function with SQS?

推荐答案

当使用 SQS 作为 AWS Lambda 的事件源时,AWS Lambda 会定期轮询配置的 SQS 队列以获取新消息.虽然官方文档对此并不清楚,但 博客文章宣布该功能 详细介绍:

When using SQS as an event source for AWS Lambda, AWS Lambda regularly polls the configured SQS queue to fetch new messages. While the official documentation isn't clear really about that, the blog post announcing that feature goes into the details:

当最初创建并启用 SQS 事件源映射时,或者在没有流量的一段时间后首次出现消息时,Lambda 服务将开始使用五个并行长轮询连接轮询 SQS 队列.

When an SQS event source mapping is initially created and enabled, or when messages first appear after a period with no traffic, then the Lambda service will begin polling the SQS queue using five parallel long-polling connections.

根据 AWS 文档,从 AWS Lambda 到 SQS 的长轮询的默认持续时间为 20 秒.

According to the AWS documentation, the default duration for a long poll from AWS Lambda to SQS is 20 seconds.

这会导致 AWS Lambda 函数每 20 秒向 SQS 发出 5 次请求而没有显着负载,总计每天约 21600 次,接近您遇到的 20000 次.

That results in five requests to SQS every 20 seconds for AWS Lambda functions without significant load, which sums up to the ~21600 per day, which is close to the 20000 you're experiencing.

虽然增加长轮询持续时间似乎是减少请求数量的一种简单方法,但这是不可能的,因为 AWS Lambda 默认使用的 20 秒已经是 SQS 队列的最大可能持续时间.在将 SQS 用作 AWS Lambda 的事件源时,恐怕没有简单的方法可以减少对 SQS 的请求.相反,是否值得评估另一个事件源(如 SNS)是否也适合您的用例.

While increasing the long poll duration seems like an easy way to decrease the number of requests, that's not possible, as the 20 seconds AWS Lambda is using by default is already the maximum possible duration for an SQS queue. I'm afraid there is no easy way to decrease the requests to SQS, when using it as event source for AWS Lambda. Instead depending it could be worth evaluating if another event source, like SNS, would fit your use case as well.

这篇关于SQS 触发的 AWS Lambda 增加 SQS 请求计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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