10

I recently started working with GraphQL and have been able to successful set it up on AWS Lambda giving me a "serverless" architecture. However I would like to utilize GraphQL Subscriptions for more realtime functionality.

I understand that AWS Lambda doesn't allow WebSockets, since the connections only last as long as the function runs or the timeout limit is reached.

But is there some way to setup the GraphQL backend so that it can utilize subscriptions and keep it within AWS services and have it scale like a "serverless" application.

Something like using AWS Lambda for GraphQL Queries and Mutations and then a different AWS service for GraphQL Subscriptions.

Adrian Hall
  • 7,990
  • 1
  • 18
  • 26
Dan
  • 2,299
  • 2
  • 20
  • 41

3 Answers3

7

AWS AppSync was announced this week (Nov. 29th) it supports graphQL subscriptions.

Dan Crawford
  • 183
  • 1
  • 5
  • This is correct, more info here: https://docs.aws.amazon.com/appsync/latest/devguide/real-time-data.html – Richard Dec 29 '17 at 17:45
  • AppSync seems like a perfect fit for what you are looking for. You can upload your schema and use lambda to implement any custom logic via resolvers. AppSync handles subscriptions out of the box and allows you to subscribe to any mutation in your API by adding a subscription field with the `@aws_subscribe(mutations: ["myMutationName"])` directive. – mparis Feb 22 '18 at 19:26
0

The only serverless service that supports WebSockets on AWS is IoT. I know that the name sounds strange, but it works fine for web browsers.

You will need to bundle the AWS IoT SDK in the fronted to subscribe and publish to topics and to use Cognito or IAM to retrieve temporary credentials for your client. You can set restrictions, so the client will be able to subscribe/publish only for a specific topic.

I don't know exactly how GraphQL subscriptions work, but I imagine that your clients will be subscribed to a topic and, every time that a data changes, one Lambda function will be triggered. This Lambda will be able to publish a notification to a topic and all clients subscribed to this topic will receive the message.

Zanon
  • 29,231
  • 20
  • 113
  • 126
  • I was looking into using AWS IoT but was confused on the GraphQL subscription integration. I'll keep looking into that tho, maybe I can turn in into the solution. – Dan Jul 02 '17 at 16:28
  • @dan have you implemented this feature ? if you have please give me step i need a help to create graphql subscription on AWS Lambda. – Dharmesh Vasani Sep 28 '17 at 09:58
  • @DharmeshVasani I didn't continue implementing this feature but it can be down rather simply buy just running a websocket server on EC2. My solution for that particular project was to just move my entire GraphQL stack to https://www.graph.cool/ and then I later migrated to Firebase for it easy realtime integration. – Dan Sep 28 '17 at 16:14
  • @dan Thanks for the reply. – Dharmesh Vasani Sep 28 '17 at 16:47
0

I had started using google cloud functions, but then moved to zeit now which is serverless but I am also able to use subscriptions. Maybe you can have a look there too

perrosnk
  • 835
  • 2
  • 13
  • 23