Skip to content

Latest commit

 

History

History
 
 

sls-components-appsync-example

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Example AppSync API

This will create an AppSync API with a single Lambda connection, lambda layer for dependencies, IAM role, and AppSync API.

Setup

Create .env file

AWS_ACCESS_KEY_ID=XXXX
AWS_SECRET_ACCESS_KEY=XXXX
$ npm run setup

Deploy

ALL

$ npm run deploy all

IAM

$ npm run deploy iam

Layer

$ npm run deploy layer

Lambda

$ npm run deploy lambda

AppSync

$ npm run deploy appsync

Test

Steps

  1. Navigate to AWS Console

  2. Search for AWS AppSync and select your API

  3. Open Queries

  4. Add query and run

query getUsersById {
  getUsersById(id: "1") {
    name
  }
}
  1. View result
{
  "data": {
    "getUsers": [
      {
        "name": "ryan"
      },
      {
        "name": "tyler"
      }
    ]
  }
}

Steps if the component doesn't attach everything

  1. Confirm that you have an API Key created

  2. Manually copy the GraphQL schema in from this project (components/appsync/src/schema.graphql) and save the schema

  3. Manually create a DataSource of AWS Lambda pointed at the lambda function you deployed in this stack (components/lambda)

  4. Navigate to Schema in the AppSync console, select the GraphQL Query of getUsers, manually set the request mapping template and response mapping template copying from components/appsync/src/vtl

  5. Open the queries tab and run

query getUsers {
    getUsers {
        name
    }
}
  1. View result
{
  "data": {
    "getUsers": [
      {
        "name": "ryan"
      },
      {
        "name": "tyler"
      }
    ]
  }
}