Serverless AppSync Plugin

2.10.5 · active · verified Sun Apr 19

The `serverless-appsync-plugin` extends the Serverless Framework to enable seamless deployment and management of AWS AppSync GraphQL APIs. Currently at stable version 2.10.5, the plugin receives regular updates, including bug fixes and new features, with several minor releases in late 2025. It differentiates itself by offering deep integration into the Serverless ecosystem, allowing developers to define AppSync schemas, data sources (Lambda, DynamoDB, HTTP, RDS, None), resolvers (VTL and JavaScript), authentication methods (API_KEY, AWS_IAM, AMAZON_COGNITO_USER_POOLS, OPENID_CONNECT), custom domains, caching, and Web Application Firewall (WAF) configurations directly within their `serverless.yml` or `serverless.ts` files. This declarative approach significantly simplifies the provisioning and updating of complex AppSync infrastructure, providing CLI commands and exposing CloudFormation variables for easy referencing of deployed resources.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a minimal Serverless.ts configuration using the plugin to deploy an AppSync API with an API key, a basic GraphQL schema, a Lambda data source, and a resolver. It sets up a 'hello' query backed by a Lambda function. To run this, you would also need a `schema.graphql` file and a `src/handlers/hello.handler` function.

import type { AWS } from '@serverless/typescript';

const serverlessConfiguration: AWS = {
  service: 'my-appsync-service',
  frameworkVersion: '3',
  plugins: [
    'serverless-appsync-plugin'
  ],
  provider: {
    name: 'aws',
    runtime: 'nodejs18.x',
    region: 'us-east-1',
    stage: 'dev',
    environment: {
      AWS_REGION: '${aws:region}',
    }
  },
  appSync: {
    name: '${self:service}-${sls:stage}-api',
    authentication: {
      type: 'API_KEY',
    },
    schema: 'schema.graphql', // Ensure this file exists at the root
    resolvers: {
      'Query.hello': {
        dataSource: 'helloLambda',
      },
    },
    dataSources: {
      helloLambda: {
        type: 'AWS_LAMBDA',
        config: {
          functionName: 'hello',
        },
      },
    },
    apiKeys: [
      {
        name: 'defaultApiKey',
      },
    ],
  },
  functions: {
    hello: {
      handler: 'src/handlers/hello.handler', // Ensure this file and handler exist
      events: [
        {
          http: {
            method: 'get',
            path: '/hello',
          },
        },
      ],
    },
  },
};

module.exports = serverlessConfiguration;

view raw JSON →