Why isn't SQS an event source for lambda?

与世无争的帅哥 提交于 2021-01-27 10:48:32

问题


AWS Lambda functions have a bunch of event sources but SQS ain't one.

Why is that? I would have thought it was a good fit.


回答1:


On 28 JUN 2018 AWS Lambda Adds Amazon Simple Queue Service to Supported Event Sources.




回答2:


To some extent; yes I do agree with your view point.

But If you really think of difference between SQS and SNS is that (as John rightly pointed out) SQS is supposed to make things asynchronus... It is like a queue which can be consumed when needed. Queue to be consumed whenever suppose Agent is available. SQS is to maintain workflows which can have lots of lag between different activities. For close to realtime operations SNS/Kinesis are better solutions.

If you want Lambda to be invoked; I think better architecture would be to send message to SNS and let Lambda get invoked.




回答3:


Amazon SQS is a queueing service, designed as a buffer for holding messages until they are consumed by an application. SQS is typically used where a backlog occurs prior to the consuming application.

AWS Lambda, however, is a highly parallel service that can run functions in parallel. Lambda functions are triggered by an event, such as uploading a file to Amazon S3 or receiving data via Amazon Kinesis.

I don't have a definite answer as to why Lambda cannot be triggered by SQS, but I'd guess it is because there is no need to do this. Instead of sending a message to Amazon SQS, the originating application should simply invoke the AWS Lambda function directly. This is a simpler process, with less moving parts.

There is a default limit of 1000 concurrent Lambda functions. If this is not enough, Lambda queues the requests and you can also request a limit increase.




回答4:


Here is a good blog post that shows you how to setup SQS as an event source for Lambda in code. Example in Terraform:

# Event source from SQS
resource "aws_lambda_event_source_mapping" "event_source_mapping" {
  event_source_arn = "${var.terraform_queue_arn}"
  enabled          = true
  function_name    = "${aws_lambda_function.test_lambda.arn}"
  batch_size       = 1
}

https://medium.com/appetite-for-cloud-formation/setup-lambda-to-event-source-from-sqs-in-terraform-6187c5ac2df1



来源:https://stackoverflow.com/questions/45317369/why-isnt-sqs-an-event-source-for-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!