FVod
FVod

Reputation: 2295

Invoke Lambda when an SQS message is sent

I'd like to invoke a lambda each time an SQS message is sent. I have tried setting up a Cloudwatch event's rule with the following pattern:

{
  "source": [
    "aws.sqs"
  ]
}

Unfortunately, the lambda is never invoked. I have already ensured that the lambda's role has the SQS policy. How can I achieve that?

Upvotes: 1

Views: 1397

Answers (2)

Stin
Stin

Reputation: 201

AWS have recently introduced SQS as trigger for Lambda, which can be invoked automatically for message in SQS.

Upvotes: 0

Michael - sqlbot
Michael - sqlbot

Reputation: 179364

CloudWatch Events can only be used for catching events from services that generate events.

SQS doesn't generate events.

The simplest way to achieve what you are looking for is to create an SNS topic and subscribe both the SQS queue and the Lambda function to the topic. Then, instead of sending messages to the queue directly, you publish the message to the topic, and SNS drops it into the queue and invokes Lambda.

http://docs.aws.amazon.com/sns/latest/dg/SNS_Scenarios.html#SNSFanoutScenario

Upvotes: 7

Related Questions