Reputation: 2319
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.
Upvotes: 10
Views: 2692
Reputation: 925
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
Upvotes: 0
Reputation: 203
AWS AppSync was announced this week (Nov. 29th) it supports graphQL subscriptions.
Upvotes: 7
Reputation: 30710
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.
Upvotes: 0