3
votes

Does AWS lambda provide support for listening to SQS queue? I found some examples which says one can do that but I am not sure if AWS lambda explicity provide support for that. When I create the lambda function, then I found one blueprint for SQS. So,

4

4 Answers

3
votes

I linked to it in your other thread - these are the supported event sources. Notice that cloudwatch events are one of the possible event types. You could set up a Lambda to, for example, run every minute and poll an SQS queue. You cannot directly trigger a Lambda off of an SQS queue.

3
votes

Good news, this feature was released yesterday!

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

Read the announcement blog post here: https://aws.amazon.com/blogs/aws/aws-lambda-adds-amazon-simple-queue-service-to-supported-event-sources/

AWS Serverless Model supports a new event source as following:

Type: SQS
 PropertiesProperties:
  QueueQueue: arn:aws:sqs:us-west-2:012345678901:my-queue arn:aws:sqs:us-west-2:0123456789 # NOTE: FIFO SQS Queues are not yet supported
  BatchSize: 10

And this is how it can be configured from the AWS Console UI:

lambda sqs event source

1
votes

You can make your lambda function poll the queue using the SQS API. You could use SNS to trigger the Lambda function.

1
votes

Update: AWS Lambda can now be triggered from Amazon SQS queues.


Old answer:

Rather than having AWS Lambda poll an Amazon SQS queue, the application that sends the message to SQS queue should instead directly invoke the Lambda function. This could be done in several ways:

  • Direct invocation via an AWS API call
  • Sending a message to an Amazon SNS topic, with the Lambda function subscribed to the topic
  • Calling a function via AWS API Gateway, which can then trigger a Lambda function

The extra step of putting a message into an SQS queue is not necessary.