AWS AppSync
AWS AppSync Developer Guide

Resolver Mapping Template Reference for RDS

The AWS Appsync RDS resolver mapping templates allow developers to send SQL queries to an Data API for Aurora Serverless and get back the result of these queries.

NOTE: This feature is only supported for the Serverless Aurora Data API. The Data API for Aurora Serverless is a Beta release. It should only be used for testing, not in production and is subject to the AWS Terms of Service including section 1.10.

Request Mapping Template

The RDS request mapping template is fairly simple:

{ "version": "2018-05-29", "statements": [], "variableMap": {} }

Here is the JSON schema representation of the Lambda request mapping template, once resolved.

{ "definitions": {}, "$schema": "http://json-schema.org/draft-07/schema#", "$id": "http://example.com/root.json", "type": "object", "title": "The Root Schema", "required": [ "version", "statements", "variableMap" ], "properties": { "version": { "$id": "#/properties/version", "type": "string", "title": "The Version Schema", "default": "", "examples": [ "2018-05-29" ], "enum": [ "2018-05-29" ], "pattern": "^(.*)$" }, "statements": { "$id": "#/properties/statements", "type": "array", "title": "The Statements Schema", "items": { "$id": "#/properties/statements/items", "type": "string", "title": "The Items Schema", "default": "", "examples": [ "SELECT * from BOOKS" ], "pattern": "^(.*)$" } }, "variableMap": { "$id": "#/properties/variableMap", "type": "object", "title": "The Variablemap Schema" } } }

The following is an example of request mapping template with a static query:

{ "version": "2018-05-29", "statements": [ "select title, isbn13 from BOOKS where author = 'Mark Twain'" ] }

Version

Common to all request mapping templates, version defines the version that the template uses. version is required. The "2018-05-29" is the only version supported for the Amazon RDS mapping templates.

"version": "2018-05-29"

Statements

The statements array is a placeholder for the developer provided queries. Currently, we support up to two queries per request mapping template. The following is possible:

{ "version": "2018-05-29", "statements": [ "insert into BOOKS VALUES ('$ctx.args.newBook.author', '$ctx.args.newBook.title', '$ctx.args.newBook.ISBN13')", "select * from BOOKS WHERE isbn13 = '$ctx.args.newBook.isbn13'" ] }

Currently, AppSync supports up to two statements.

VariableMap

The variableMap is an optional field which contains aliases that can be used to make the SQL statements shorter and more readable. For example the following is possible:

{ "version": "2018-05-29", "statements": [ "insert into BOOKS VALUES (:AUTHOR, :TITLE, :ISBN13)", "select * from BOOKS WHERE isbn13 = :ISBN13" ], "variableMap": { ":AUTHOR": "$ctx.args.newBook.author", ":TITLE": "$ctx.args.newBook.title", ":ISBN13": "$ctx.args.newBook.isbn13" } }

Appsync will use the variable map value to construct the queries that are sent to the Aurora Serverless Data API. For example the two queries that AWS Appsync will send to Amazon RDS will be (assming “$ctx.args.newBook.author"='Mark Twain', "$ctx.args.newBook.title"='Adventures of Huckleberry Finn' and "$ctx.args.newBook.isbn13"='978-1948132817'):

INSERT INTO BOOKS VALUES ('Mark Twain', 'Adventures of Huckleberry Finn', '978-1948132817');

and

SELECT from BOOKS where isb13='978-1948132817';