AWS API Gateway Websockets -- where is the connectionID?

To resolve this, go to your AWS console -> open your AWS CloudShell (Top right in your dashboard)

For the WebSocket server using HTTP_PROXY, you need to modify the @connect route to add the connectionId

1- Enter in the shell:

# List all integrations

aws apigatewayv2 get-integrations --api-id xxxxxxxxx

# Update all @connect integration

aws apigatewayv2 update-integration --integration-id zzzzzzzz --api-id xxxxxxxxx --request-parameters 'integration.request.header.connectionId'='context.connectionId'

2- Don't forget to deploy after or it won't work

Why AWS don't provide you with the connectionId? Because they want you to use Lambda.


Thanks everyone on trying to document AWS API Gateway.

To be able to send data from AWS Websocket API Gateway to your integrated service using VPC Link do the following:

  1. Uncheck Use Proxy Integration

  2. Save

  3. Set Request Template as in the following image: Request Template Set Up of AWS Websocket API Gateway

  4. This will allow to get connectionId, query, body in the body of request.

  5. Save

  6. Click on Add Integration Response on the top right

  7. Set Integration Response as in the following image: Integration Response Setup

8. Hopefully, it will work. If not, please figure out by testing and then put in the answers here for others. Thank you.

I would suggest forget any other type of integration and just use lambda. Because the next problem you will face is getting query parameters that were passed at the time of connection in integration of disconnect.


To add content to the integration request, you'll need to use a Request Template.

  1. Turn off HTTP Proxy Integration for your route. (You can't modify the request otherwise.)
  2. Save your changes. (the Request Templates section won't appear until you do so.)
  3. Set your Template Selection Expression. This is used to look up a value from the incoming request object. (If you want to match all incoming requests, enter \$default. Note the slash. Full documentation here.)
  4. Set your Template Key. This is compared against the value selected by the Template Selection Expression. If it's a match, the template is used. (If you want to match all incoming requests, enter $default. Note the absence of a slash.)
  5. Click your Template Key to open the template editor. This is where you enter your template that will be sent to your integration endpoint as the body of the request. For example, if you want to forward the connection ID and the incoming query parameters to the integration endpoint, you can use the following:
{
    "myConnectionIdProperty": "$context.connectionId",
    "myQueryParams": $input.params()
}

Documentation for variables available to you in the template expression can be found here.

(Note that while $request is a valid variable in the Template Selection Expression, it is not a valid variable in the template itself. Use $input instead there.)