title: Serverless WebSockets - No method found matching route @connections/* for http method POST
body: <p>I'm using Serverless Framework to host my WebSocket, which has the typical $connect, $disconnect, $default, etc methods that updates my connections db:</p>
  <pre><code>case '$connect':
    await dynamoDb.put({
      TableName: process.env.CONNECTIONS_TABLE,
      Item: {
        connectionId,
        // Expire the connection an hour later. This is optional, but recommended.
        // You will have to decide how often to time out and/or refresh the ttl.
        ttl: parseInt((Date.now() / 1000) + 3600)
      }
    }).promise();
  </code></pre>
  <p>My WebSocket setup is:</p>
  <pre><code>WebSocket URL: wss://1111111111.execute-api.ap-southeast-2.amazonaws.com/dev/
  Connection URL: https://1111111111.execute-api.ap-southeast-2.amazonaws.com/dev/@connections
  </code></pre>
  <p>My HTTP setup is:</p>
  <pre><code>Invoke API at: https://222222222.execute-api.ap-southeast-2.amazonaws.com/dev/
  </code></pre>
  <p><a href="https://i.stack.imgur.com/MML6M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MML6M.png" alt="image" /></a></p>
  <p>I have a broadcast function which I am using to send data to the connections, which I am invoking with:</p>
  <pre><code>sls invoke --function broadcast --data '{ \&quot;body\&quot;: \&quot;Hello from server\&quot; }'
  </code></pre>
  <p>The source sends a message to each connection, as provided in the params of the request:</p>
  <pre><code>async function sendMessage(connectionId, body) {
    try {
      await apig.postToConnection({
        ConnectionId: connectionId,
        Data: body
      }).promise();
    } catch (err) {
      // Ignore if connection no longer exists
      if(err.statusCode !== 400 &amp;&amp; err.statusCode !== 410) {
        throw err;
      }
    }
  }
  
  async function getAllConnections(ExclusiveStartKey) {
    const { Items, LastEvaluatedKey } = await dynamoDb.scan({
      TableName: process.env.CONNECTIONS_TABLE,
      AttributesToGet: [ 'connectionId' ],
      ExclusiveStartKey
    }).promise();
  
    const connections = Items.map(({ connectionId }) =&gt; connectionId);
    if(LastEvaluatedKey) {
      connections.push(...await getAllConnections(LastEvaluatedKey));
    }
    return connections;
  }
  
  module.exports.handler = async function(event, context) {
    const { body } = event;
    const connections = await getAllConnections();
  
    await Promise.all(
      connections.map(connectionId =&gt; sendMessage(connectionId, body))
    );
  }
  </code></pre>
  <p>A connection can be established (I can connect to the WebSocket), however when I try to invoke this function I am receiving the error:</p>
  <blockquote>
  <p>No method found matching route @connections/ZE4SDfSJSwMCJ4g%3D for http method POST.</p>
  </blockquote>
  <p>The <code>ZE4SDfSJSwMCJ4g</code> is my connectionId, which exists in my database. I am unsure if this routing issue has to do with my HTTP API and my WebSocket API being pointed at different API Gateway URL?</p>
  <p>I appreciate the help!</p>