How can I send a response body back to a client from an AWS Lambda function through API Gateway WebSocket

1

API gateway configured to call a lambda application for $default messages.

The Java Lambda application where I return an APIGatewayV2WebSocketResponse object as a response. Before returning, I set the response code and response body.

However, the client does not receive these responses. How can I ensure that the client receives the response code and body.

2 réponses
0
Réponse acceptée

Hi, you need to post the message using the Api Gateway Management API, indicating the Connection Id where you need to send your message to and your API url. You can use the aws sdk to do this, you can use the postToConnection method in the AmazonApiGatewayManagementApiClient class. Please check

AWS
répondu il y a 2 mois
0

Hi, You could enable 2-way communication on API Gateway websocket to send the response back to client. After 2-way communication is enabled,

  • For proxy integrations, API Gateway automatically passes the backend output to the caller as the complete payload. There is no integration response.
  • For non-proxy integrations, you must set up at least one integration response:

Kindly refer this doc for more details.

Additionally, you could also use "postToConnection" as explained in post, However this requires additional code to be written on the integration side to Post the message back to client

profile pictureAWS
Bony_T
répondu il y a 2 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