Trigger Lambda Manually to read from SQS

Viewed 523

Is it possible to create a lambda which is triggered manually to read from an SQS.

I have an SQS queue which is constantly receiving messages, I want to process them when I want to (not continuous sync processing).

Can I have something like a start/stop lambda, where I start the lambda, and it consumes actively from SQS and when I stop it stops consuming

1 Answers

Normally, an AWS Lambda function is configured to "trigger" from an Amazon SQS queue. Whenever a message arrives, a Lambda function would be triggered.

However, instead of configuring a trigger, you could code an AWS Lambda function to call ReceiveMessages() on the queue itself. The Lambda function would then be responsible for calling DeleteMessage() after the message has been processed.

You can invoke a Lambda function at any time by using the Invoke() command.

The only decision you would need to make is whether the Lambda function should process:

  • One message per invocation, or
  • One batch of messages (up to 10) per invocation, or
  • Run a loop that keeps retrieving messages from the queue until the queue is empty or until the Lambda function times-out (which could leave a message partially processed, so it isn't a good idea)
Related