Skip to main content

GraphQL endpoint in AWS AppSync

Basic example of defining an AWS AppSync endpoint from Pulumi

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-appsync
cd pulumi-examples/aws-ts-appsync

This example shows how to set up a basic GraphQL endpoint in AWS AppSync. The endpoint contains one query and one mutation that get and put items to a Dynamo DB table.

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Node.js

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Set the AWS region to deploy into:

    Terminal window
    pulumi config set aws:region us-east-2
  3. Install dependencies:

    Terminal window
    npm install
  4. Deploy the stack:

    Terminal window
    pulumi up
    Previewing update (dev):
    ...
    Updating (dev):
    ...
    Resources:
    + 10 created
    Duration: 20s
  5. Check the deployed GraphQL endpoint:

    Terminal window
    pulumi stack output endpoint
    pulumi stack output key
    curl -XPOST -H "Content-Type:application/graphql" -H "x-api-key:$(pulumi stack output key)" -d '{ "query": "mutation AddTenant { addTenant(id: \"123\", name: \"FirstCorp\") { id name } }" }' "$(pulumi stack output endpoint)"
    https://***.appsync-api.us-east-2.amazonaws.com/graphql
    ***sensitivekey***
    {
    "data": {
    "addTenant": {
    "id": "123",
    "name": "FirstCorp"
    }
    }
    }

Cleaning up#

  1. Run pulumi destroy to tear down all resources.

  2. To delete the stack itself, run pulumi stack rm. Note that this command deletes all deployment history from the Pulumi console.

Related

The infrastructure as code platform for any cloud.