Reputation: 416
I'm writing a mobile application in Swift 3 and using AWS APIGateway, Lambda and RDS. In the POST method, I'm passing a unique identifier in one of the elements of the body such as:
us-east-1:xxxxxxxx-55b0-4917-82e3-85b3b093fa9c
However, in a GET method, I'm using a Request Path to retrieve this user record and passing this value. However, I'm guessing it's getting encoded since it's a request path and resulting with:
us-east-1%3Axxxxxxxx-55b0-4917-82e3-85b3b093fa9c
Once it hits Lambda this way (and my RDS), it will not find the record due to the escaping of the colon. As such, can I "unescape" this value in the Integration Request template?
I've tried a template such as:
#set($inputRoot = $input.path('$'))
{
"user_identity" : "$util.decodeURIComponent($input.params('useridentity'))"
}
However, that doesn't work. I get the following in my logs:
Thu Aug 17 02:32:47 UTC 2017 : HTTP Method: GET, Resource Path: /user/us-east-1%3Axxxxxxxx-55b0-4917-82e3-85b3b093fa9c
Thu Aug 17 02:32:47 UTC 2017 : Endpoint request body after transformations: {
"user_identity" : ""
}
I've also tried using decodeURI but that gives me the same result. What am I missing here?
Upvotes: 5
Views: 1102
Reputation: 416
Dang! I literally found the answer a few minutes after I posted this. Here was the solution:
#set($inputRoot = $input.path('$'))
{
"user_identity" : "$util.urlDecode($input.params('useridentity'))"
}
The urlDecode function did the trick. I hope this helps someone else!!
Upvotes: 7