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

1 réponse
1
Réponse acceptée

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
INGÉNIEUR EN ASSISTANCE TECHNIQUE
Bony_T
répondu il y a 8 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions