top of page

AWS - Mapping Template in API Gateway with VTL

  • Writer: Anh Nguyen tuan
    Anh Nguyen tuan
  • Mar 8, 2023
  • 1 min read

Use Case:

  • When API Gateway integrates with AWS Service (like SQS) and need to transform data by using Request & Response Template.

AWS Console:

  • Go to the menu 'Resources' of an API in the service 'API Gateway'

  • Select a method. Click to the link 'Integration Request'

  • Go to Mapping Templates section, click a content type in the list of Content-Type. You will see the section of Request Template.

Notes:

For example, API gateway integrates with SQS:


requestTemplates:
  application/json: |-
    Action=SendMessage&MessageBody={"field1":$util.urlEncode($input.json('$.field1'))}


Tricks:

  • Convert String to Integer or Long by this snippet

## Convert String to Integer
#set($Val=0)
$Val.parseInt('123')
## Convert String to Long
#set($Val=100000000000000)
$Val.parseLong('123')




LInk Reference: https://aws.amazon.com/blogs/compute/using-api-gateway-mapping-templates-to-handle-changes-in-your-back-end-apis/


Recent Posts

See All

Comments


bottom of page