Mapping templates and variables

You can map the requests and responses in API Gateway by using API Gateway's body mapping templates, based on the Apache VTL and JSONPath expressions. 

The $input variable provided by the API Gateway represents the input payload (a request payload or response payload, based on the case) and the parameters available to the template. The function $input.json() retrieves part of the JSON, as specified by a JSONPath expression. In JSONPath, $ represents the outer-level JSON object. $input.json('$.user.name') returns the value of the field name within the user object, and $input.json('$.greeting.time') returns the value of the field time within the greeting object. Similarly, $input.json('$.message') returns the value of the message field.

Aside from $input, API Gateway also provides $context, $stageVariables, and $util variables. The $context variable holds the contextual information, such as the apiId, authorizer propertiesprincipalId, httpMethod, error details, accountId, apiKey, cognitoAuthenticationProvider details, sourceIp, pathprotocol, status, stage, and so on. The variable $stageVariables can be used to refer to stage variables. The $util variable has utility functions that can be used in mapping templates, such as escapeJavaScript(), parseJson(), urlEncode(), urlDecode(), base64Encode(), and base64Decode()

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.39.60