I am using this construct in my s-templates.json as part of my requestParameters:
"params": "{#foreach($param in $input.params().path.keySet())\"$param\": \"$util.escapeJavaScript($input.params().path.get($param))\" #if($foreach.hasNext),#end#end}",
When I call my API from API Gateway, my Lambda receives the params as a string, and I have to call JSON.parse on the string.
When I call my API from serverless-offline, my Lambda receives the params as an object (which I actually prefer).
Would be great if both returned the same response, which I guess means offline should match API Gateway/Lambda.
Hi @alshamma, you've just pointed out the plugin's main issue! This is due to the difference of implementation between the Java Velocity parser AWS uses and the JavaScript Velocity parser we use (an external library).
To fix your issue one should call JSON.stringify on each velocity output, put this raises issues too.
I'll keep this one open as a reminder.
I just ran into this issue as well. #if() statements seem to act differently between AWS/Offline.
Assuming $elem.value is undefined, the following works offline:
#if($elem.value)
Value is defined.
#end
But on AWS the text is still rendered...
Then I tried:
#if($elem.value != $null)
Value is defined.
#end
Which works on AWS, but throws an error offline...
I also tried:
#if($elem.value != null)
Value is defined.
#end
Which worked offline but not on AWS.
I found a workaround on this page that seems to work the same between AWS/Offline:
#if("$!elem.value" != "")
Value is defined.
#end
But this is kind of ugly...
+1
We run to an issue when we deployed our lambda to aws. It took us a while to realise that we weren't wrapping the response's body with JSON.stringify - the logs in aws didn't tell us anything and everything works locally with serverless offline.
At the moment we have to remember to use JSON.stringify every time, which is not ideal.
any update?
@alireza8101 do you have some repro code about the issue?
@alireza8101 do you have some repro code about the issue?
unfortunately no