AppSync Direct Go Lambda resolvers with DynamoDB

This project contains a sample CDK template for using Direct Lambda resolvers using Go with an AppSync API. Direct Lambda resolvers allows you to write resolver logic in a language of your choice and circumvent the use of VTL.

In the given pattern, AWS AppSync will provide a arguments from context payload to your AWS Lambda function and a default of a Lambda function’s response to a GraphQL type.



To each Query and Mutation of Graphql in AppSyncApi, one Lambda Resolver is attachted. It handles a business logic of the request.

It’s defined as NoteService (Microservice) in Go. Each Lambda function has its own and single responsibility to interact with DynamoDB and it returns the reuslt back to AppSyncApi over ResultTemplateMapping.

In this project, you can learn both cdk example and go microserivce structure.


  1. Clone the project to your local working directory
git clone
  1. Change the working directory to cdk’s directory
cd cdk
  1. Install dependencies
npm install
  1. This project uses typescript as client language for AWS CDK. Run the given command to compile typescript to javascript
npm run build
  1. Synthesize CloudFormation template from the AWS CDK app
cdk synth
  1. Deploy the stack to your default AWS account and region. The output of this command should give you the GraphQL URL and API Key for your AppSync API.
cdk deploy


You can test your AppSync API and Direct Lambda resolver by running a query from AWS AppSync console.

You can run a query directly from your terminal or via postman:

# install curl.
# optional: install jq.
# replace <graphqlUrl> and <apiKey> with the outputs values from `cdk deploy`
curl --location --request POST '<graphqlUrl>' \
--header 'x-api-key: <apiKey>' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query { listNotes }","variables":{}}' | jq


Run the given command to delete the resources that were created. It might take some time for the CloudFormation stack to get deleted. This will delete all deployed resources including cloudwatch lamdba log groups.

cdk destroy






View Github