This project emulates aspects of the mapping environment to make it easier to test templates.
Scala
Switch branches/tags
Nothing to show
Clone or download

README.md

AWS API Gateway Mapping Template Playground

The AWS API Gateway uses Apache Velocity to transform requests into JSON. This project emulates aspects of the mapping environment to make it easier to test templates.

History: this project exists to improve and test the application/x-www-form-urlencoded template created by avilewin in an API Gateway post. The version used here derives from work by Christian E Willman

Using this Playground

Two ways:

  1. Use the runner.scala script to set up and execute a template; or

  2. Write a ScalaTest test for your template in src/test/scala.

Either way what you do is:

  • write a .vm template
  • set up a Context, Input instance
  • use Runner to execute your scenario

Status

The gateway defines a variety of methods and values. Their status in this project is described below.

Descriptions in italic are from the AWS Documentation.

Util

  • $util.escapeJavaScript() - Escapes the characters in a string using JavaScript string rules.
  • $util.urlEncode() - Converts a string into "application/x-www-form-urlencoded" format.
  • $util.urlDecode() : String => String - Decodes an "application/x-www-form-urlencoded" string.
  • $util.base64Encode() - Encodes the data into a base64-encoded string.
  • $util.base64Decode() - Decodes the data from a base64-encoded string.

Context

  • $context.apiId - _ The identifier API Gateway assigns to your API._
  • $context.httpMethod - _ The HTTP method used. Valid values include: DELETE, GET, HEAD, OPTIONS, PATCH, POST, and PUT._
  • $context.identity.accountId - _ The AWS account ID associated with the request._
  • $context.identity.apiKey - _ The API owner key associated with your API._
  • $context.identity.caller - _ The principal identifier of the caller making the request._
  • $context.identity.cognitoAuthenticationProvider - _ The Amazon Cognito authentication provider used by the caller making the request. Available only if the request was signed with Amazon Cognito credentials._
  • $context.identity.cognitoAuthenticationType - _ The Amazon Cognito authentication type of the caller making the request. Available only if the request was signed with Amazon Cognito credentials._
  • $context.identity.cognitoIdentityId - _ The Amazon Cognito identity ID of the caller making the request. Available only if the request was signed with Amazon Cognito credentials._
  • $context.identity.cognitoIdentityPoolId - _ The Amazon Cognito identity pool ID of the caller making the request. Available only if the request was signed with Amazon Cognito credentials._
  • $context.identity.sourceIp - _ The IP address of the API caller as determined by the X-Forwarded-For header. Note that this should not be used for security purposes. To get the full value of X-Forwarded-For addresses you can define the X-Forwarded-For header in your API and then map it to your integration._
  • $context.identity.user - _ The principal identifier of the user making the request._
  • $context.identity.userAgent - _ The User Agent of the API caller._
  • $context.identity.userArn - _ The Amazon Resource Name (ARN) of the effective user identified after authentication._
  • $context.requestId - _ An automatically generated ID for the API call._
  • $context.resourceId - _ The identifier API Gateway assigns to your resource._
  • $context.resourcePath - _ The path to your resource. For more information, see Create a Resource._
  • $context.stage - _ The deployment stage of the API call (for example, Beta or Prod)._

Input

  • $input.json(x) - _ This function evaluates a JSONPath expression and returns the results as a JSON string._
  • $input.params() - _ Returns a map of all the request parameters of your API call._
  • $input.params(x) - _ Returns the value of a method request parameter from the path, query string, or header value (in that order) given a parameter name string x._
  • $input.path(x) Only implemetned for input $ so far- _ Takes a JSONPath expression string (x) and returns an object representation of the result. This allows you to access and manipulate elements of the payload natively in Apache Velocity Template Language (VTL)._

StageVariables

TODO

References