I'm making a service that requests data through AWS API Gateway directly from DynamoDB.
I want to use mapping templates on Integration Response, to remove DynamoDB item types and give a user expected simple JSON.
From DynamoDB I get this
{
"Count": 10,
"Items": [
{
"acc_secret": {
"S": "12345"
},
"acc_apikey": {
"S": "abcde"
},
"login": {
"S": "user"
}
}
]
}
And I want to get items format like this
[
{
"acc_secret": "12345",
"acc_apikey": "abcde",
"login": "user"
},
{
"acc_secret": "12345",
"acc_apikey": "abcde",
"login": "user"
}
]
I have a code to change the format, but for explicit values.
#set($inputRoot = $input.path('$'))
[
#foreach($elem in $inputRoot.Items) {
"param1": "$elem.param1.S",
"param2": "$elem.param2.S",
"param3": "$elem.param3.S"
}#if ($foreach.hasNext),#end
#end
]
but in my case I can have different types of keys, not only string, and a lot more items, I can't declare them all in a mapping template at once.
Help me please to dynamically transform item keys in cycle. Thanks.