Hey guys. I have a NestJS app running on a k8s cl...
# sst
a
Hey guys. I have a NestJS app running on a k8s cluster, all fine. But I want to hook these services to an SQS queue. The way I found to do this is: 1. Doing “polling” of the queue all the time 2. Adding a lambda triggered-by-sqs which can call my Service. 3. What else? is there a way to hook an endpoint directly to SQS?
a
a
I don’t want to do long polling.
If I can do a lambda trigger + webhook.
Right?
a
Sure. That sounds like something that will add cost, complexity, and latency. The k8s cluster is running and consuming resources. All the Lambda AWS Service does is long poll the SQS queue, and then trigger your lambda when something is returned, which will then trigger your code in k8s. Maybe polling from within NestJS isn't possible?
a
It is posible.
But I want to avoid polling.
SQS already has hooks/consumers for Lambda.
So the chain will be…. SQS -> Lambda -> k8s Service (nestjs)
a
I understand. I am pointing out though that Lambda Service (not your function) makes that happen by long polling. You may not be doing the polling, but it is happening.
a
I see.
I don’t think is like that.
I think is SQS calling Lambda, the opposite?
But not sure, to be honest.
In your concept, “somebody” is doing the polling, in low level.
I thought SQS had a list of “listeners” and will call each of them, in this case, a lambda-listener.
Like… 1 message comes in -> deliver to all the listeners.
a
Some Lambda integrations get called, and some poll. EventBridge calls lambda. Streaming data sources, like SQS, Kinesis, S3, dynamoDB, (and more!) work by way of AWS doing the polling for you.
This is just implementation detail, but you sound hung up on not wanting long polling. I don't know the reason for that, but just pointing out that many Lambda event sources do work that way.
A reason in favor of putting Lambda in between SQS and your NestJS containers is to decouple your system. Maybe you want to be able to hit the API in NestJS from other places (like the client?), and so let that stand alone and the (other source) => SQS => Lambda is a separate thing that your NestJS app doesn't need to know even exists.
That does bring up a possible security aspect. If you go the NestJS HTTP API route, is security of that endpoint an issue?
t
Is SNS helpful here? https://aws.amazon.com/sns/
You can use SNS and SQS together to create a range of messaging patterns.
f
Second @Adam Fanello here. Lambda polls from the Queue behind the scene. Polling doesn’t necessarily mean delays if that’s ur concern. U can poll in a way that meets ur latency requirement ie. long poll vs short polling. https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-short-and-long-polling.html