如何限制topic的消费率?
How to limit the consuming rate from a topic?
有没有其他人解决了以下问题?
我有 SNS 主题 充满了来自 S3 的事件并且有 Lambda 函数 订阅了这个主题当数千个事件被放入该主题时,lambda 函数由于超过并发限制而受到限制。
我不想请求增加并发执行的限制,但我会减少该主题的并发消耗,但我没有找到有关如何操作的信息。谢谢。
关于 SNS 的几个选项:
1) SNS 最大接收速率
设置SNS Maximum Receive Rate。这将限制发送给订阅者的 SNS 消息,但如果您有太多消息以至于它们在处理之前将被丢弃,则可能不是一个好的选择。来自文档:
You can set the maximum number of messages per second that Amazon SNS
sends to a subscribed endpoint by setting the Maximum receive rate
setting. Amazon SNS holds messages that are awaiting delivery for up
to an hour. Messages held for more than an hour are discarded.
如果您一次只接收数千个事件,将最大接收速率设置为 Lambda 的 default concurrent execution limit“100”可能值得一试。
正如@kndrk 指出的那样,此限制目前仅适用于 SNS 主题的 HTTP/HTTPS 订阅者。要解决此问题,您可以 expose your lambda function via AWS API Gateway 并将该端点订阅到 SNS 主题,而不是直接订阅 lambda 函数。
2) 来自 SQS 的进程
Subscribe an SQS queue to the SNS topic and process messages from the queue, rather than directly from the sns topic. A single invokation of SQS ReceiveMessage 一次只能处理 10 条消息,因此您可能更容易控制。
还值得注意的是,您可以发布S3 Events directly to AWS Lambda。
有没有其他人解决了以下问题?
我有 SNS 主题 充满了来自 S3 的事件并且有 Lambda 函数 订阅了这个主题当数千个事件被放入该主题时,lambda 函数由于超过并发限制而受到限制。
我不想请求增加并发执行的限制,但我会减少该主题的并发消耗,但我没有找到有关如何操作的信息。谢谢。
关于 SNS 的几个选项:
1) SNS 最大接收速率
设置SNS Maximum Receive Rate。这将限制发送给订阅者的 SNS 消息,但如果您有太多消息以至于它们在处理之前将被丢弃,则可能不是一个好的选择。来自文档:
You can set the maximum number of messages per second that Amazon SNS sends to a subscribed endpoint by setting the Maximum receive rate setting. Amazon SNS holds messages that are awaiting delivery for up to an hour. Messages held for more than an hour are discarded.
如果您一次只接收数千个事件,将最大接收速率设置为 Lambda 的 default concurrent execution limit“100”可能值得一试。
正如@kndrk 指出的那样,此限制目前仅适用于 SNS 主题的 HTTP/HTTPS 订阅者。要解决此问题,您可以 expose your lambda function via AWS API Gateway 并将该端点订阅到 SNS 主题,而不是直接订阅 lambda 函数。
2) 来自 SQS 的进程
Subscribe an SQS queue to the SNS topic and process messages from the queue, rather than directly from the sns topic. A single invokation of SQS ReceiveMessage 一次只能处理 10 条消息,因此您可能更容易控制。
还值得注意的是,您可以发布S3 Events directly to AWS Lambda。