title: AWS API Gateway store JSON to DynamoDB
body: <p>I have an issue trying to use API Gateway as a proxy to DynamoDB.</p>
  
  <p>Basically it works great if I know the structure of the data I want to store but I cannot manage to make it dynamic regardless of the payload structure.</p>
  
  <p>There are many websites explaining how to use API Gateway as a proxy to DynamoDB.
  None that I found explains how to store a JSON object though.</p>
  
  <p>Basically I send this JSON to my API endpoint:</p>
  
  <pre><code>{
      "entryId":"abc",
      "data":{
          "key1":"123",
          "key2":123
      }
  }
  </code></pre>
  
  <p>If I map using the following template, the data gets put in my database properly</p>
  
  <pre><code>{ 
      "TableName": "Events",
      "Item": {
          "entryId": {
              "S": "abc"
          },
          "data": {
              "M": {
                "key1": {
                  "S": "123"
                },
                "key2": {
                  "N": "123"
                }
              }
          }
      }
  }
  </code></pre>
  
  <p>However, I don't know the structure of "data" hence why I want the mapping to be dynamic, or even better, I would like to avoid any mapping at all.</p>
  
  <p>I managed to make it dynamic but all my entries are of type String now:</p>
  
  <pre><code>      "data": { "M" : {
        #foreach($key in $input.path('$.data').keySet())
        "$key" : {"S": "$input.path('$.data').get($key)"}#if($foreach.hasNext),#end
        #end }
                }
  </code></pre>
  
  <p>Is it possible to get the type dynamically?
  I am not quite sure how API Gateway mapping works yet.</p>
  
  <p>Thank you for you help.</p>
  
  <p>Seb</p>