Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway - How do I get the date/timestamp/epoch in a body mapping template?

I need to include the request time in the body mapping template for an API Gateway method. Is there a date/time variable or function? I couldn't find anything in the template reference.

Example body mapping template:

Action=SendMessage&MessageBody=$util.urlEncode("{""timestamp"":""TIMESTAMP_HERE"",""body-json"":$input.json('$'),""params"":""$input.params()""}")
like image 527
John Himmelman Avatar asked Dec 17 '16 01:12

John Himmelman


People also ask

How do I use a mapping template in API gateway?

You must define the model in order to have API Gateway to generate a SDK or to enable basic request validation for your API. You don't have to define any model to create a mapping template. However, a model can help you create a template because API Gateway will generate a template blueprint based on a provided model.

How do I add a mapping template to AWS API gateway?

Navigate to the API Gateway console, choose the StoreFront API and open the GET method of the /orders resource. On the Method Execution details page, choose Integration Response. Expand the default response mapping (HTTP status 200), and expand the Mapping Templates section. Choose Add Mapping Template.

What is VTL in API gateway?

API Gateway uses Velocity Template Language (VTL) engine to process body mapping templates for the integration request and integration response.


1 Answers

UPDATE: API Gateway just added two new context variables http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

$context.requestTime    The CLF-formatted request time (dd/MMM/yyyy:HH:mm:ss +-hhmm).
$context.requestTimeEpoch   The Epoch-formatted request time.

API gateway doesn't support this currently. Its been requested before on the forums - https://forums.aws.amazon.com/thread.jspa?messageID=697658&. We have this feature in our backlog, but unfortunately I can't commit to any timelines.

like image 103
Abhigna Nagaraja Avatar answered Sep 28 '22 07:09

Abhigna Nagaraja