Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I put a response in a separate lambda behind websocket api gateway?

I have a AWS API Gateway with websocket connection. And there is a lambda (LA) which is called by this API gateway and it sends a request to another service along with the websocket connection ID. After that it exists. There is another lambda LB which is listening on some backend data store. The data store service will call LB if there is any update event. The event includes websocket conneciton ID. And I'd like to let LB send an update event to API gateway which forward this event to clients over websocket connection. This is a communication mode in my mind. My question is whether API gateway supports such mode. If yes, how does LB send response event to API gateway and to clients?

The communication looks like below screenshot. The question is whether it works? how the response lambda send event to API gateway?

enter image description here

I have added the Integration response as below. There are Integration Request and Integration Response. But I can only set up one lambda for both of them. How can I make different lambda for request and response?

enter image description here

enter image description here

like image 508
Joey Yi Zhao Avatar asked Nov 22 '25 15:11

Joey Yi Zhao


1 Answers

Yes it works.

API Gateway WebSocket APIs are bidirectional. A client can send messages to a service, and services can independently send messages to clients.

There are two ways to send response from your lambda to api gateway;

1) An integration can send a response, which is returned to the client by a route response that you have defined. Here are the details

2) You can use the @connections API to send a POST request. For more information, see Use @connections commands in your backend service. Here are the details

Your case looks like option 2. Invoking api gateway using connection api at your lambda.

like image 162
Ersoy Avatar answered Nov 24 '25 04:11

Ersoy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!