9

I have a GraphQL Apollo server running in AWS Fargate (ECS), I'm using API Gateway (HTTP proxy integration) on top. The purpose of that API is to make use of Cognito Authorizer in addition to secure SSL (HTTPS).

This is working fine as far as Graphql HTTP operations are involved (query and mutation)

However Graphql subscriptions are using websockets. The Proxy integration doesn't seem to handle the upgrade to the websocket protocol.

I've tried to define a new websocket API following this documentation: https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api.html

But nothing seems to work for me. I've tried defining $connect, $disconnect and $default with an HTTP proxy integration to the Apollo server endpoint, but I keep getting:

Error during WebSocket handshake: Unexpected response code: 400

Is it possible to proxy an existing websocket API using Amazon API Gateway? Is HTTP proxy integration the correct integration to use?

Note: The client implementation is fine, as my subscriptions works if I put the direct url to the Apollo server websocket endpoint.

plus-
  • 45,453
  • 15
  • 60
  • 73
  • You may have to use a NGINX server as the HTTP proxy that accepts websocket connections on behalf of ECS from API Gateway. A sample NGINX config for Beanstalk can be found here https://gist.github.com/RobinBuschmann/c42a413ecedee463e5bd8e613ddd8d04 – Suraj Bhatia Feb 25 '20 at 20:13
  • have you tried https://github.com/apollographql/subscriptions-transport-ws – C.Gochev Feb 26 '20 at 09:57
  • @C.Gochev Yes, that's what I'm already using client side. – plus- Feb 26 '20 at 14:44
  • 2
    The problem is that the API Gateway WebSockets API converts the WebSocket connection into HTTP Requests, but that is not what Apollo is expecting. There is [a library](https://github.com/michalkvasnicak/aws-lambda-graphql) that makes Apollo work with the WebSockets API, but is more geared to Lambda and thereby uses DynamoDB for persistance. So not a perfect solution. – Rain336 Mar 02 '20 at 08:15
  • @Rain336 thanks, I will look at it. – plus- Mar 02 '20 at 08:51

0 Answers0