title: Serverless WebSocket route responses
body: <p>I am using <code>serverless</code> to create a WebSocket service, for which I am able to successfully trigger my WebSocket routes locally, using <code>serverless-offline</code> and for the deployed service.</p>
  
  <p>The issue I am having now is responding to those WS events.</p>
  
  <p>I am able to use <code>AWS.ApiGatewayManagementApi.postToConnection</code> to respond to my local WebSocket events, though I cannot seem to get the <code>return</code> value of my handler to actually send a WebSocket event in response, as <a href="https://github.com/dherault/serverless-offline#websocket" rel="nofollow noreferrer">these serverless-offline docs</a> and <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-route-response.html" rel="nofollow noreferrer">these AWS docs</a> suggest.</p>
  
  <p>The <code>serverless.yml</code> route:</p>
  
  <pre class="lang-yaml prettyprint-override"><code>  ws-custom:
      handler: handler.wsCustom
      events:
        - websocket:
            route: custom
            routeResponseSelectionExpression: $default
  </code></pre>
  
  <p>The handler:</p>
  
  <pre class="lang-js prettyprint-override"><code>module.exports.wsCustom = async (event) =&gt; {
    const body = JSON.parse(event.body);
    console.log('WebSocket `custom` event!', event);
  
    return {
      statusCode: 200,
      body: JSON.stringify({ message: `Hello, ${body.name}!` }),
    };
  }
  </code></pre>
  
  <p>Invoking the function in my browser JavaScript:</p>
  
  <pre class="lang-js prettyprint-override"><code>ws.send(JSON.stringify({ 'action': 'custom', 'name': 'kevbot' }));
  </code></pre>
  
  <p>The result is that my <code>serverless-offline</code> logs (or CloudWatch in the case of the deployed project) will create an event with the log successfully, but my client will receive no events in response.
  Does anyone know how I can do this with the return value of the handler?</p>
  
  <p>EDIT:</p>
  
  <p>The problem seems to exist within my <code>serverless-offline</code> setup. I will attempt to get it working locally and will create an issue necessary.</p>