Apollo server for AWS Lambda with WebSocket subscriptions support over API Gateway v1 + v2)
Last updated 12 days ago by michalkvasnicak .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install aws-lambda-graphql 
SYNC missed versions from official npm registry.


CircleCI aws-lambda-graphql package version

⚠️ This documentation is currently for 1.0.0-alpha.X package which supports only subscriptions-transport-ws and drops the legacy protocol and client support! To use old version that supports legacy protocol and client see the link 0.13.0 below.

????Documentation for aws-lambda-graphql0.13.0

Use Apollo Server Lambda with GraphQL subscriptions over WebSocket (AWS API Gateway v2).

With this library you can do:

Table of contents


yarn add aws-lambda-graphql graphql graphql-subscriptions
# or
npm install aws-lamda-graphql graphql graphql-subscriptions


There is a quick start guide.

## API


Creates an Apollo Lambda server.


All options from Apollo Lambda Server and

  • connectionManager (IConnectionManager, required)
  • eventProcessor (IEventProcessor, required)
  • onError ((err: any) => void, optional) - use to log errors from websocket handler on unknown error
  • subscriptionManager (ISubscriptionManager, required)
  • subscriptions (optional)
    • onConnect(messagePayload: object, connection: IConnection, event: APIGatewayWebSocketEvent, context: LambdaContext): Promise<boolean|object> | object | boolean (optional) - Return an object to set a context to your connection object saved in the database e.g. for saving authentication details
    • onOperation(message: OperationRequest, params: ExecutionParams, connection: IConnection): Promise<ExecutionParams>|ExecutionParams (optional)
    • onOperationComplete(connection: IConnection, operationId: string): void (optional)
    • onDisconnect(connection: IConnection): void (optional)
    • waitForInitialization (optional) - if connection is not initialised on GraphQL operation, wait for connection to be initialised or throw prohibited connection error. If onConnect is specified then we wait for initialisation otherwise we don't wait. (this is usefull if you're performing authentication in onConnect).
      • retryCount (number, optional, default 10) - how many times should we try to check the connection state?
      • timeout (number, optional, default 50ms) - how long should we wait (in milliseconds) until we try to check the connection state again?


Creates an AWS Lambda API Gateway v1 handler. Events are handled by apollo-server-lambda


Creates an AWS Lambda API Gateway v2 handler that supports GraphQL subscriptions over WebSocket.


Creates an AWS Lambda handler for events from events source (for example DynamoDBEventStore). This method internally work with IEventProcessor.

DynamoDBEventProcessor: IEventProcessor

AWS Lambda DynamoDB stream handler. DynamoDBEventProcessor is used internally by Server.

Options (optional)

  • onError ((err: any) => void, optional)

DynamoDBConnectionManager: IConnectionManager

IConnectionManager implementation that stores information about connections to DynamoDB table, performs communication with them, etc.

Each connection is stored as IConnection object.


  • connectionsTable (string, optional, default: 'Connections') - name of DynamoDB table used to store connections
  • subscriptions (ISubscriptionManager, required) - subscription manager used to register subscriptions for connections.

DynamoDBEventStore: IEventStore

IEventStore implemenation that used AWS DynamoDB as storage for published events.


  • eventsTable (string, optional, default: 'Events') - events DynamoDB table name
  • ttl (number, optional, default: 2 hours)
    • optional TTL for events set in seconds
    • the value is stored as ttl field on the row (you are responsible for enabling TTL on given field)

DynamoDBSubscriptionManager: ISubscriptionManager

ISubscriptionManager implementation that used AWS DynamoDB as storage for subscriptions.

Stores subscriptions to a subscriptions table as event: string and subscriptionId: string.Make sure to set up the key schema as event: HASH and subscriptionId: RANGE.

Stores subscription operations to a subscription operations table as subscriptionId: string. Make sure to set up the key schema as subscriptionId: HASH.


  • subscriptionsTableName (string, optional, default: 'Subscriptions')
  • subscriptionOperationsTableName - (string, optional, default: 'SubscriptionOperations')



  • context (object) - connection context data provided from GQL_CONNECTION_INIT or onConnect. This data is passed to graphql resolvers' context. All values should be JSON seriablizable.
  • isInitialized (boolean) - is connection initialised? Basically if you use onConnect then this value is false until the onConnect successfully resolves with non false value.

Context creator function

Context creator function accepts IContext and returns an object or Promise that resolves to an object.


Internal context passed to the Context creator function.


  • event - AWS Lambda event that invoked the handler
  • lambdaContext - AWS Lambda handler context
  • $$internal - internal object passed by this library
    • connection (IConnection) - current connection that invoked the execution or is associated with an operation
    • connectionManager (IConnectionManager)
    • operation (OperationRequest) - operation associated with current invokation
    • pubSub (PubSub) - PubSub instance used by event store
    • subscriptionManager (ISubscriptionManager)


PubSub implementation that publishes events / subscribes to events using underlying event store.


  • eventStore: IEventStore - event store used to publish events / subscribe to events


  • Chat App - React app
  • Chat Server
    • contains AWS Lambda that handles HTTP, WebSocket and DynamoDB streams
    • also includes serverless.yaml file for easy deployment

Current Tags

  • 1.0.0-alpha.4                                ...           latest (12 days ago)
  • 0.13.0                                ...           version-0.x (2 months ago)

28 Versions

  • 1.0.0-alpha.4                                ...           12 days ago
  • 1.0.0-alpha.3                                ...           17 days ago
  • 1.0.0-alpha.2                                ...           2 months ago
  • 1.0.0-alpha.1                                ...           2 months ago
  • 1.0.0-alpha.0                                ...           2 months ago
  • 0.13.0                                ...           2 months ago
  • 0.12.3                                ...           3 months ago
  • 0.12.2                                ...           3 months ago
  • 0.12.1                                ...           3 months ago
  • 0.12.0                                ...           3 months ago
  • 0.11.0                                ...           3 months ago
  • 0.10.0                                ...           4 months ago
  • 0.9.1                                ...           4 months ago
  • 0.9.0                                ...           4 months ago
  • 0.8.1                                ...           5 months ago
  • 0.8.0 [deprecated]           ...           5 months ago
  • 0.7.2                                ...           5 months ago
  • 0.7.1                                ...           5 months ago
  • 0.7.0                                ...           7 months ago
  • 0.6.0                                ...           8 months ago
  • 0.5.0                                ...           8 months ago
  • 0.4.0 [deprecated]           ...           8 months ago
  • 0.3.1                                ...           9 months ago
  • 0.3.0                                ...           9 months ago
  • 0.2.1                                ...           9 months ago
  • 0.2.0                                ...           9 months ago
  • 0.1.0                                ...           a year ago
  • 0.1.0-alpha.0                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 29
Last Day 0
Last Week 0
Last Month 65
Dependencies (5)
Dev Dependencies (6)

Copyright 2014 - 2016 © |