AWS API Gateway stores JSON in DynamoDB

I have a problem using Gateway API as a proxy for DynamoDB.

Basically, it works great if I know the structure of the data I want to keep, but I cannot make it dynamic regardless of the structure of the payload.

There are many websites that explain how to use the API gateway as a proxy server for DynamoDB. No, what I found explains how to save a JSON object.

I basically send this JSON to the API endpoint:

{
    "entryId":"abc",
    "data":{
        "key1":"123",
        "key2":123
    }
}

If I match using the following pattern, the data fits correctly in my database

{ 
    "TableName": "Events",
    "Item": {
        "entryId": {
            "S": "abc"
        },
        "data": {
            "M": {
              "key1": {
                "S": "123"
              },
              "key2": {
                "N": "123"
              }
            }
        }
    }
}

However, I do not know the structure of the "data", so I want the display to be dynamic or even better, I would generally avoid any comparison.

, String:

      "data": { "M" : {
      #foreach($key in $input.path('$.data').keySet())
      "$key" : {"S": "$input.path('$.data').get($key)"}#if($foreach.hasNext),#end
      #end }
              }

? , API Gateway.

.

+4
2

- Dynamodb. Lambda - , Dynamodb.

+1
-1

All Articles