1 minute read

Setting up a GraphQL server in JavaScript on AWS Lambda can be a powerful way to build scalable and flexible APIs for your web and mobile applications. In this blog post, we will walk through the steps of setting up a GraphQL server using Node.js and the express-graphql library, and deploying it to AWS Lambda.


Before we get started, you will need to have the following tools installed:

  • Node.js and npm (or yarn)

  • Terraform

Setting up your project

First, create a new directory for your project and initialize a new Node.js project using npm or yarn. The folder structure is like this

- graql-server
yarn add @apollo/server graphql @as-integrations/aws-lambda


import { ApolloServer } from '@apollo/server'
import { startServerAndCreateLambdaHandler } from '@as-integrations/aws-lambda'

const typeDefs = gql`
  type Query {
    hello: String

const resolvers = {
  Query: {
    hello: () => {
      return 'Hello world!'

const server = new ApolloServer({
  csrfPrevention: true,
  cache: 'bounded',

console.log('Starting graphql server')

export const handler = server.createHandler()

Provision AWS lambda function

Please refer to the lambda provision page.

Send hello query on GraphQL Playground

Make sure you have Homebrew installed on your machine and install GraphQL Playground using Homebrew.

brew install --cask graphql-playground

Open up Spotlight Search by pressing cmd + space and rRun GraphQL Playground by typing graphql-playground. This will start a local instance of GraphQL Playground

In the GraphQL Playground, enter the following query in the left panel:

query {

Click the “Play” button to send the query. You should see a response like:

  "data": {
    "hello": "Hello world!"