How can i convert string value from path param to int in Mapping templates of aws api gateway

168 views Asked by At

I try to using api gateway and query data direct to dynamo db. I has epoch time in path param and i tried to minus epoch by one day to query data in dynamodb but it not work. I tried convert by Interger.paserInt and some way but not work Please help me This is my body mapping templates

#set($epoch = $input.params('epoch'))
#set($secondInADay = 43200)
#set($start = $epoch - $secondInADay)

{
    "TableName":"my-table",
    "KeyConditionExpression":"#type_alias=:v1 AND epoch BETWEEN :startTime AND :endTime",
    "ExpressionAttributeValues":{
        ":v1":{"S":"m"},
        ":startTime":{"N":"$util.urlDecode($start.toString())"},
        ":endTime":{"N":"$util.urlDecode($epoch.toString())"}
    },
    "ExpressionAttributeNames":{"#type_alias":"my hashkey"}
}
1

There are 1 answers

2
Leeroy Hannigan On

To convert it to a number you can use the following syntax:

$Integer.parseInt($input.params('epoch'))