AWS AppSync
AWS AppSync Developer Guide

Resolver Mapping Template Reference for HTTP

The AWS AppSync HTTP resolver mapping templates enable you to shape requests from AWS AppSync to any HTTP endpoint, and responses from your HTTP Endpoint back to AWS AppSync. By using mapping templates, you can provide hints to AWS AppSync about the nature of the operation to be invoked. This section describes the different mapping templates for the supported HTTP resolver.

Request Mapping Template

{ "version": "2018-05-29", "method": "PUT|POST|GET|DELETE|PATCH", "params": { "query": Map, "headers": Map, "body": string }, "resourcePath": string }

Following is the JSON schema representation of the HTTP request mapping template, after it's resolved:

{ "$id": "http://aws.amazon.com/appsync/request-mapping-template.json", "type": "object", "properties": { "version": { "$id": "/properties/version", "type": "string", "title": "The Version Schema ", "default": "", "examples": [ "2018-05-29" ], "enum": [ "2018-05-29" ] }, "method": { "$id": "/properties/method", "type": "string", "title": "The Method Schema ", "default": "", "examples": [ "PUT|POST|GET|DELETE|PATCH" ], "enum": [ "PUT", "PATCH", "POST", "DELETE", "GET" ] }, "params": { "$id": "/properties/params", "type": "object", "properties": { "query": { "$id": "/properties/params/properties/query", "type": "object" }, "headers": { "$id": "/properties/params/properties/headers", "type": "object" }, "body": { "$id": "/properties/params/properties/body", "type": "string", "title": "The Body Schema ", "default": "", "examples": [ "" ] } } }, "resourcePath": { "$id": "/properties/resourcePath", "type": "string", "title": "The Resourcepath Schema ", "default": "", "examples": [ "" ] } }, "required": [ "version", "method", "resourcePath" ] }

Following is an example of an HTTP POST request, with a text/plain body:

{ "version": "2018-05-29", "method": "POST", "params": { "headers":{ "Content-Type":"text/plain" }, "body":"this is an example of text body" }, "resourcePath": "/" }

Version

REQUEST Mapping Template only

Common to all request mapping templates, version defines the version that the template uses. version is required.

"version": "2018-05-29"

Method

REQUEST Mapping Template only

HTTP method or verb (GET, POST, PUT, PATCH, or DELETE) that AWS AppSync sends to the HTTP endpoint.

"method": "PUT"

ResourcePath

REQUEST Mapping Template only

The resource path that you want to access. This, along with the endpoint in the HTTP data source, forms the URL that the AWS AppSync service makes a request to.

"resoucesPath": "/v1/users"

When the mapping template is evaluated, this path is sent as part of the HTTP request, including the HTTP endpoint. For example, the previous example might translate to the following:

PUT <endpoint>/v1/users

Params Field

REQUEST Mapping Template only

Used to specify what action your search performs, most commonly by setting the query value inside the body. However, there are several other capabilities that can be configured, such as the formatting of responses.

  • headers

    The header information, as key-value pairs. Both the key and the value must be strings. For example:

"headers" : { "Content-Type" : "application/json" }

Note: You cannot set the following HTTP headers:

HOST CONNECTION USER-AGENT EXPECTATION TRANSFER_ENCODING CONTENT_LENGTH
  • query

    Key-value pairs that specify common options, such as code formatting for JSON responses. Both the key and the value must be a string. The following example shows how you can send a query string as ?type=json:

"query" : { "type" : "json" }
  • body

    The body contains the HTTP request body that you choose to set. The request body is always a UTF-8 encoded string unless the content type specifies the charset.

"body":"body string"