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:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-ts-appsynccd pulumi-examples/aws-ts-appsyncThis 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.
Deploying and running the Pulumi App#
-
Create a new stack:
Terminal window pulumi stack init dev -
Set the AWS region:
$ pulumi config set aws:region us-east-2 -
Restore NPM modules via
npm installoryarn install. -
Run
pulumi upto preview and deploy changes:$ pulumi upPreviewing update (dev):...Updating (dev):...Resources:+ 10 createdDuration: 20s -
Check the deployed GraphQL endpoint:
$ pulumi stack output endpointhttps://***.appsync-api.us-east-2.amazonaws.com/graphql$ pulumi stack output key***sensitivekey***$ 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)"{"data": {"addTenant": {"id": "123","name": "FirstCorp"}}}
Clean up#
-
Run
pulumi destroyto tear down all resources. -
To delete the stack itself, run
pulumi stack rm. Note that this command deletes all deployment history from the Pulumi console.