pythondjangoamazon-web-servicesamazon-dynamodbboto

dynamodb boto put_item of type Map "M"


Has anyone successfully performed a put operation of a map into dynamodb using boto (python)?

I basically need to put a json object. So far I have only been able to put it as json string but I cannot find an example of inserting a map anywhere.

Thanks a lot.


Solution

  • Since it does not looks like boto supports JSON in its high-level API interface, you have to use the low-level API interface and annotate your JSON object into a DynamoDB-supported wire format as such:

    "time": {
        "M": {
          "creation_timestamp_utc": {
            "S": "2012-08-31T03:35:56.881Z"
          },
          "localtime": {
            "S": "12:25:31"
          },
          "received_timestamp_utc": {
            "S": "2012-08-31T07:50:50.367Z"
          },
          "spacecraft_clock": {
            "S": "399657440.746"
          }
        }
    

    In the above snippet, M is used to denote a "map" object, and S is used to denote the attribute type of each of the entries. You can find more information on what annotations to use for each type here.

    I can understand why this is extremely annoying to do though, so you could always open an issue (perhap there is already one opened) at https://github.com/boto/boto/issues/new so they are aware of the feature request.