Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Server
✓ import { Server } from 'aws-lambda-graphql'
✗ const { Server } = require('aws-lambda-graphql')
Since v1.0.0-alpha, package is ESM-only. Use import statement.
SubscriptionManager
✓ import { SubscriptionManager } from 'aws-lambda-graphql'
✗ const SubscriptionManager = require('aws-lambda-graphql').SubscriptionManager
Named import for subscription manager. Must be instantiated with Redis connection.
default (The library as a whole)
✓ import awsLambdaGraphql from 'aws-lambda-graphql'
✗ const awsLambdaGraphql = require('aws-lambda-graphql')
Default export exists but is discouraged; prefer named exports.
Creates an Apollo Server Lambda with WebSocket subscriptions, DynamoDB connection and event processors, Redis pub/sub.
import { Server, SubscriptionManager, DynamoDBConnectionManager, DynamoDBEventProcessor } from 'aws-lambda-graphql';
import Redis from 'ioredis';
import { ApolloServer } from 'apollo-server-lambda';
const typeDefs = `
type Query { ping: String }
type Subscription { messageSent: String }
`;
const resolvers = {
Query: { ping: () => 'pong' },
Subscription: {
messageSent: {
subscribe: (_, __, { pubsub }) => pubsub.asyncIterator(['MESSAGE_SENT'])
}
}
};
const redis = new Redis(process.env.REDIS_URL ?? '');
const subscriptionManager = new SubscriptionManager({ redis });
const connectionManager = new DynamoDBConnectionManager({ tableName: 'Connections' });
const eventProcessor = new DynamoDBEventProcessor({ tableName: 'Events' });
const server = new Server({
server: new ApolloServer({ typeDefs, resolvers }),
connectionManager,
eventProcessor,
subscriptionManager,
subscriptions: {
onConnect: async (messagePayload, connection, event, context) => {
return { user: { id: '123' } };
}
}
});
export const handler = server.createHandler();
Errors
Common errors & fixes
Cannot find module 'aws-lambda-graphql'
Package not installed or wrong import path.
fixRun 'npm install aws-lambda-graphql graphql graphql-subscriptions ioredis aws-sdk' or install missing peer dependencies.
Error: Cannot use GraphQLSchema "[object Object]" from another module or realm.
Multiple copies of 'graphql' module due to mismatched versions or dependency resolution.
fixEnsure only one version of graphql in node_modules. Use npm dedupe or yarn resolutions.
TypeError: Class extends value undefined is not a constructor or null
Missing peer dependency 'graphql-subscriptions' or incompatible version.
fixInstall graphql-subscriptions@^1.0.0 and ensure no duplicate versions.
Connection timeout when initializing WebSocket
API Gateway WebSocket route not configured or Lambda function not connected.
fixConfigure $connect, $disconnect, and $default routes in API Gateway to invoke your Lambda. Check IAM permissions.
Upgrade
Version history
1.0.0-alpha.24latest on npm
Audit
Dependencies
aws-sdkrequiredRequired for AWS Lambda and API Gateway interaction
graphqlrequiredPeer dependency for GraphQL schema and execution
graphql-subscriptionsrequiredFor implementing GraphQL subscriptions
ioredisrequiredRequired for subscription state management and pub/sub