如何触发基于SQS队列的事件?
我正在创建一个SQS队列(下面的示例),我知道SQS队列可以直接与lambda互动,因此,一旦消息传来,Lambda就可以处理触发器。我认为Lambda正在轮询此队列,以查看是否有任何消息。这是否意味着Lambda每分钟(或类似的事情)运行,而且费用也很高? SQ可以添加延迟以调用Lambda吗?还是有更好的设置,可以说触发一个lambda,以使其不会为每条消息的每条消息发射lambda,而是一次或一次间隔一段时间间隔?
AWSTemplateFormatVersion: '2010-09-09'
Description: Template to create a queue
Resources:
queue:
Type: AWS::SQS::Queue
Properties:
QueueName: 'myQueue'
FifoQueue: true
Outputs:
QueueURL:
Description: Queue URL
Value: !Ref queue
I'm creating a sqs queue (sample below), I understand sqs queue can be directly intergrated with a lambda , such that as soon as a message comes , lambda can process the trigger. i assume lambda is polling this queue , to see if there are any message. does this means lambda is running every minute(or something similar) and also is that costly in terms of charges?
can sqs add a delay to invoke the lambda? or is there a better set up, which allows to say trigger a lambda such that it doesn't fire lambda for every message that comes in but may be do it for every few message at a time or some time interval?
AWSTemplateFormatVersion: '2010-09-09'
Description: Template to create a queue
Resources:
queue:
Type: AWS::SQS::Queue
Properties:
QueueName: 'myQueue'
FifoQueue: true
Outputs:
QueueURL:
Description: Queue URL
Value: !Ref queue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设Lambda正在轮询队列时,您是正确的。但是,Lambda本身并未运行以检查消息。 lambda使用事件源映射在您的情况下,Lambda对事件来源进行了轮询。
至于您的lambda流程有多少消息, “ 部分要获取更多详细信息,但是您可以设置等待时间(批处理窗口),并限制一次lambda进程的消息(批量大小)。默认情况下,Lambda在队列中等待10条消息或5分钟,以先到者为准。设置事件源时,可以更改这些值。在的Amazon SQS 。
You are correct in assuming lambda is polling the queue; however, the lambda itself is not running to check for messages. Lambda uses Event Source Mappings that works somewhat separately from lambda to poll the Event Source, in your case SQS.
As for how many messages your lambda processes, see the "Batching Behavior" section to get more detail, but you can set a wait time (Batch window) and a limit to how many messages a lambda processes at once (Batch size). By default, lambda waits for 10 messages in the queue or for 5 minutes, whichever comes first. When setting up your event source, these values can be changed. Checkout this guide from Amazon on a more detailed description on Using Lambda with Amazon SQS.