amazon-web-servicesaws-lambdaamazon-sqs

Triggering multiple lambda functions from one SQS trigger


I'm not sure if I understand AWS Lambda - SQS triggers correctly. Can I possibly configure it in such a way that one SQS queue can trigger different lambda functions depending on the message body or a message attribute?

My use case: I have three different lambda functions (processCricket, processFootball, processTennis) each of which perform a unique function. I have a single queue (processGame) which receives messages. Each message on the queue has a attribute "type" which is either "Cricket", "Football" or "Tennis". Can I invoke a different lambda function depending on the "type" on the message?

Option 1: Configure SQS to trigger a different lambda function depending on the type (Not sure if I can do this)

Option 2: Configure one lambda function which can check type and then call the other lambda functions depending on its type

Option 3: Create separate queues for each lambda. Control which lambda processes the message by adding the message to the appropriate queue.


Solution

  • Option 1: Configure SQS to trigger a different lambda function depending on the type

    You can't know about the type until it is consumed by the lambda. So this one is not possible.

    Option 2: Configure one lambda function which can check type and then call the other lambda functions depending on its type

    Yes it is the "possible" way of first option. but it may cost "more" depending on your usage. When you consume the sqs in batch mode, then you have to invoke multiple lambdas by making multiple checks.

    Option 3: Create separate queues for each lambda. Control which lambda processes the message by adding the message to the appropriate queue.

    In my opinion, this could be the best option. You can configure different DLQ for each queue, set different batch size depending on your business rules, no need for extra lambda to increase "complexity".