Documentation
Gateway
Deployment
Serverless / On the Edge
AWS Lambda

Deploying Hive Gateway to AWS Lambda

AWS Lambda is a serverless computing platform that makes it easy to build applications that run on the AWS cloud. Hive Gateway is platform agnostic so they can fit together easily.

💡

Before you start, make sure you read the Serverless / On the Edge page.

import { APIGatewayEvent, APIGatewayProxyResult, Context } from 'aws-lambda'
import { createGatewayRuntime } from '@graphql-hive/gateway'
 
const serveRuntime = createGatewayRuntime(/* Your configuration */)
 
export async function handler(
  event: APIGatewayEvent,
  lambdaContext: Context
): Promise<APIGatewayProxyResult> {
  const response = await serveRuntime.fetch(
    event.path +
      '?' +
      new URLSearchParams((event.queryStringParameters as Record<string, string>) || {}).toString(),
    {
      method: event.httpMethod,
      headers: event.headers as HeadersInit,
      body: event.body
        ? Buffer.from(event.body, event.isBase64Encoded ? 'base64' : 'utf8')
        : undefined
    },
    {
      event,
      lambdaContext
    }
  )
 
  const responseHeaders = Object.fromEntries(response.headers.entries())
 
  return {
    statusCode: response.status,
    headers: responseHeaders,
    body: await response.text(),
    isBase64Encoded: false
  }
}