Reputation: 2729
Is it possible to retrieve the time stamp of the API gateway request in the Body Mapping Template of the Integration Request so it can only retrieve records that are greater than (or less than) the creation date?
Current Set up
API Gateway (GET) -> DynamoDB -- Response --> API Gateway
Body Mapping Template
{
"TableName": "table-name-in-dynamodb",
"ScanFilter": {
"creationDate": {
"AttributeValueList": [ { "N":"TIMESTAMP_OF_THE_API_REQUEST" } ],
"ComparisonOperator": "GT"
}
}
}
I have read that the header X-Amzn-Trace-Id can be retrieved with $input.params('X-Amzn-Trace-Id') which will return a string with the version number and time stamp. AWS API Gateway - How do I get the date/timestamp/epoch in a body mapping template?
I am still pretty new to all of this so I'm not sure how I can process the data.
Is this even possible?
Upvotes: 3
Views: 1813
Reputation: 4666
Yes it is possible. You can do :
Body Mapping Template
{
"TableName": "table-name-in-dynamodb",
"ScanFilter": {
"creationDate": {
"AttributeValueList": [ { "N":"$context.requestTimeEpoch" } ],
"ComparisonOperator": "GT"
}
}
But you have to know that $context.requestTimeEpoch
does not work in test env.
So you first need to deploy your API before using it.
all the docs about the context variables can be found here : https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Upvotes: 1