1

In my lambda function I send the receiptHandle as body data to a server. Then, this server must do the work and tell SQS to delete this message.
The problem is that the aws docs says:

...
If your function successfully processes the batch, Lambda deletes the messages from the queue. If your function is throttled, returns an error, or doesn't respond, the message becomes visible again.

Which means that if I delegate the SQS message deletion to another service and end the Lambda execution, the SQS message will be deleted by this Lambda exit, which I don't want to happen. The message's visibility timeout should remain the same also.
Is there a way to accomplish this?

1
  • I would also be interested in this possibility. The messages are to be processed in EC2, but I require a queue trigger to actually instantiate the server(s). Commented Dec 1, 2020 at 9:52

1 Answer 1

3

Is there a way to accomplish this?

No. The built-in SQS -> Lambda integration works that way (i.e., it deletes a messages from SQS once the Lambda Function returns successfully, like explained in the docs you linked and quoted), and it is not configurable.

[...] which I don't want to happen.

Why do you want to delegate the SQS message deletion to another service? What are you really trying to achieve?

Sign up to request clarification or add additional context in comments.

7 Comments

I want to delegate it to another service because it's this other service that will do the main work tasked by the SQS message. The lambda trigger acts as an orchestrator of this service and some other ones. But the only criteria for deleting the SQS message should be that this other service accomplished what it had to do (in my case, wait for players arrive in a game).
In that case, why exactly are you consuming the messages using Lambda rather than directly from this other service? Lambda isn't a good "orchestrator", it's a good "worker". For an "orchestrator" (which can wait for events, supports logic with branching, loops, custom retries, etc), you might want to check AWS Step Functions. Or if what you need is really simple (i.e., just "wait for players"), you could have your "other process" retrieve the messages from SQS itself, and then it has full control over their lifecycle.
I can't consume the SQS messages directly from the service because this service might not be the only consumer. Actually, this service is a small service coordinating a game room for a particular game match. Each match runs this dedicated small server in a container. Therefore, the lambda function is necessary because it receives a container endpoint in the body, and posts a request to the correct container.
This sounds like a broader design issue. For the type of problem you're describing, a typical pattern is to have one SQS Queue per "type of consumer" or "type of job", and then each specific consumer consumes from its specific queue. If the producer of the message knows the final destination, it could possibly write directly there; if not, it could write to an "entry" SQS Queue (like the one you have) and then a Lambda function would route it to the appropriate queue — meaning that it will receive from "entry", write to the right "specific", and then immediately delete from "entry".
This way, (1) the lambda is trivial (i.e., it only routes messages), and (2) each service has the ability to consume the messages as it sees fit. Finally, if the overall logic gets more complex than just routing messages from one entry point to a specific queue (i.e., say message A goes to worker A, which then produces a message B that should go to worker B, but sometimes A produces C that should go to worker C, and eventually C may send to B or send back to A, etc), then just multiple queues + corresponding workers + routing lambda may get too complex, and Step Functions might be better.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.