How to add a template for AWS SQS to AWS CloudWatch

I want to call the Lambda function whenever a new message is added to SQS. Please note, I don't want to add new message (s) to SQS.

What I am trying to do:

  • My app will send a message to SQS
  • Whenever a new message is added to the queue, the CloudWatch event is generated
  • CloudWatch event fires lambda

Problem:

In the AWS console while configuring CloudWatch events, I didn't find an option to add an event source, that is, the URL or name of my SQS queue.

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

+3


source to share


2 answers


I would recommend changing your approach.

Your app should publish

post to an existing SNS topic. Your SQS and Lambda must match subscribe

for this SNS topic.



Application -> publish -> SNS_TOPIC
                            -> SQS is notified
                            -> Lambda is notified

      

+2


source


SQS is not supported as a direct event source for AWS Lambda functions. If you have the properties of the queue system that you need for your use case, then you can have a Lambda function like "cron-job" 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 constantly poll SQS even during periods when you do not expect messages that are unnecessary.

The easiest way is to use SNS. Create a topic, post events to this section, don't add a message to the SQS queue, and your Lambda function is subscribed to this SNS topic. Then it will be called every time a post is posted to that SNS thread. There is a tutorial on this approach here:



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

+2


source







All Articles