API Gateway - Body Mapping Template - optional body parameters
<p>I have a POST API Gateway method to which I am sending the following application/json body in order to pass parameters from it to a Lambda that the method is connected to:</p>

<pre><code>{ 
    "otherClientId": "12345",
    "message": "Text",
    "seconds": 0,
    "hours": 0
}
</code></pre>

<p>I am using the following mapping template:</p>

<pre><code>#set($inputRoot = $input.path('$'))
{
  "authorizedUser": "$context.authorizer.principalId",
  "otherClientId": "$inputRoot.otherClientId",
  "message": "$inputRoot.message",
  "amount": $inputRoot.amount,
  "duration": $inputRoot.duration
}
</code></pre>

<p>The problem I am experiencing is that I receive a "Bad String" error when attempting to send the request without amount or duration. For some reason these parameters do not seem to be optional (but I need them to be!).
I am able to miss out other parameters, like message for instance, but not the two number parameters.</p>

<p>Has anybody else experienced this or can somebody point out the obvious that I am probably missing? The AWS documentation is a little sparse on the subject.</p>