0

I am creating a demo websocket API using AWS API Gateway onConnect and onDisconnect, I have attached Lambda functions

with code like

const AWS = require('aws-sdk');
const ddb = new AWS.DynamoDB.DocumentClient();

function addConnectionId(connectionId) {
    return ddb.delete({
        TableName: 'Chat',
        Key: {
            connectionid : connectionId,

        },

    }).promise();}


exports.handler = (event) => {
    console.log("Connection broken");
    const connectionId = event.requestContext.connectionId;
    addConnectionId(connectionId).then(() => {
        return {
            statusCode: 200, 
            body:JSON.stringify({ msg: 'connected'})
        }

    });}

but when i call it from wscat I get 502

D:>wscat -c wss://r6e1pcpjib.execute-api.ap-south-1.amazonaws.com/development
error: Unexpected server response: 502

#aws #webSocket #find-a-specialist enter image description here

I tried below article but didn't find the desired output

AWS API Gateway error response generates 502 "Bad Gateway"

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Rohit Mittal
  • 395
  • 1
  • 5
  • 18
  • I resolved it myself Issue was with data returned from handlers has to be in string format using JSON.Stringify and output returned from handler has to be in specific format. – Rohit Mittal Apr 14 '21 at 03:30

1 Answers1

0

Issue was with data returned from handlers which has to be in string format using JSON.Stringify and output returned from handler has to be in specific format.

Rohit Mittal
  • 395
  • 1
  • 5
  • 18