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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则