I am setting up an AWS API Gateway Websockets with a custom authorizer on the $connect route, as described here:
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-route-keys-connect-disconnect.html
My question is -- how do I get the connectionID, ie the identifier I can use to later broadcast to that connected client?
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:
Uncheck Use Proxy Integration
Save
Set Request Template as in the following image:
This will allow to get connectionId, query, body in the body of request.
Save
Click on Add Integration Response on the top right
Set Integration Response as in the following image:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With