can I proxy AWS API Gateway WebSocket to WebSocket?

Viewed 1687

Currently I am using the API Gateway as a kind of proxy to provide https simply

https://random-aws-name.com => http://my-domain.com

The route was $default

The integration setup is HTTP ANY -> http://my-domain.com

I am now having to setup an Websocket server on my domain that is already listening at ws://my-domain.com. I can connect directly to this socket but not using the AWS API Gateway

wss://random-aws-name.com => ws://my-domain.com

Currently I an getting unexpected error 400, using wscat

I tried to enable API gateway logging and do not see any log arrive

2 Answers

IMHO, AWS API Gateway is only able to provide a wss end point and route requests to HTTP backends only. If we already have a backend websocket server, I don't see an option in AWS API Gateway to perform such routing (Although I would be glad to be proven wrong as I have such a requirement myself.).

I actually tried giving wss:// url as the Endpoint URL but I got an error while deploying the API saying Invalid HTTP endpoint specified for URI

Most likely, the API Gateway you are currently using is not a WebSocket API, but rather an HTTP API or REST API. API Gateway has different flavors. You pick a flavor when you deploy. The flavor that you deployed is most likely not the flavor that supports WebSocket connections.

According to this documentation page, proxied WebSocket connections may only be one-way (note in blue box at bottom of page): https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-routes-integrations.html

Related