An example Terraform configuration to launch an AWS AppSync service with a Go Lambda data source.
This repo is the complete code example from a blog post I wrote called Easy AWS AppSync with Terraform.
Note: the Makefile may only run on macOS/linux, if you are on Windows you may need to build the Go lambda function another way.
- Lambda functions are in the
/functions
directory - Apache Velocity resolver templates are inside the
/resolvers
directory - The GraphQL schema is in
schema.graphql
- All Terraform config is within the following 3 files:
variables.tf
has variables used throughout the rest of the configiam.tf
contains AWS IAM roles and policiesmain.tf
contains the code for generating all other required services
- Download Terraform
- Have an existing local AWS credentials profile (this is required so Terraform has the permissions to publish your AWS service)
- Have Go installed (required to run commands to build the Go lambda function)
- Open
variables.tf
and set them to whatever you want
Note: if you want your state to persist, remove the line from
.gitignore
that says*.tfstate
. This state is essential to keep track of your AWS resources in order to successfully update or destroy them.
Warning: this will fall within the free tier for AWS, however if you have had your account for longer than 1 year you may be charged a small amount for executing AppSync queries since the free tier for AppSync is only 12 months. If you still want to deploy it, the cost should be minimal (cents, not dollars).
- Run
terraform init
to initialize terraform and fetch all the resources - Run
make build
to build the Go lambda function binary - Run
terraform plan
to view the diff and all the created resources - Run
terraform apply
to publish (it will prompt you to type "yes" to confirm)
Once this is done you can view your AppSync console and run queries to test that the Lambda data source is working!
- Run
terraform destroy
to remove all AWS services (it will prompt for "yes" again)