APIGateway Websocket enabe two-way communication not work on $connect route

0

I understand i can not use @connections api to push notify during @connect handler, cause at this time, the connection has not been established.

But why after enabled two-way communication, the $connect route response body still not push to client via websocket channel. It will be much simple since we can use this to implement somehting like server sent hello msg after client connected immediately.

Am i missing something here, or it just can not do this ? is there something i can use to implement server sent hello msg after client connected

unaki
已提問 8 個月前檢視次數 252 次
1 個回答
1
已接受的答案

Hi, Unfortunately $Connect route cannot send a response back to the client. The connection will get established successfully only when the $connect route complete its execution. Therefore, the response send by the downstream integration (like lambda function attched to $connect route) will not be send to the client. However as a workaround, You can trigger a lambda function "asynchronously" from the $connect route integration lambda function. In this new lambda functiom, you can check recursively whether the connection is established and then send a message to client using @connections api.

Client ------($Connect)------> Lambda Function--------(async Invocation)-----> Lambda function (send message using @connections api)

profile pictureAWS
支援工程師
Bony_T
已回答 8 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南