Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Even Pattern for AWS SQS in AWS CloudWatch

I want to trigger Lambda function whenever new message added to SQS. Note that I don't want to add new message (events) to SQS.

What I'm trying to do:

  1. My app will send message to SQS
  2. Whenever new message added to queue CloudWatch event gets generated
  3. CloudWatch Event triggers lambda

Problem:

In AWS console while configuring CloudWatch Events I haven't found any option to add source of event i.e. URL or Name of my SQS queue.

I'm not sure if this use case is valid but please help me out.

like image 329
Darshan Ambhaikar Avatar asked Mar 08 '23 18:03

Darshan Ambhaikar


1 Answers

EDIT: AWS now supports SQS as an event source to trigger Lambda functions. See this blog post for more details.

ORIGINAL ANSWER: SQS is not supported as a direct event source for AWS Lambda functions. If there are properties of a queueing system that you need for your use case, then you could have a "cron-job" type Lambda function that runs on a schedule, receives messages from the queue, and calls your worker Lambda function in response to each message received. The problem with this approach is that you must continually poll SQS even during periods when you don't expect messages, which incurs unnecessary cost.

The easiest approach is to use SNS instead. Create a topic, publish events to that topic instead of adding a message to an SQS queue, and have your Lambda function subscribe to that SNS topic. It will then be invoked each time a message is published to that SNS topic. There's a tutorial on this approach here:

http://docs.aws.amazon.com/lambda/latest/dg/with-sns-example.html

like image 151
Todd Price Avatar answered Mar 25 '23 08:03

Todd Price