Fork me on GitHub
#aws
<
2022-02-24
>
neil.clarke09:02:07

Hi guys - does anyone have experience with sending binary data to DynamoDB via the Cognitect AWS API?

1
jjttjj15:02:52

I've done it

jjttjj15:02:30

(aws/invoke ddb
  {:op      :PutItem
   :request {:TableName "my-table"
             :Item {:pk {:S "myData"}
                    :myData {:B (nippy/freeze {:hello :world})}}}})

(aws/invoke ddb
  {:op      :GetItem
   :request {:TableName "my-table"
             :Key       {:pk {:S "myData"}}}})

#_{:Item {:pk     {:S "myData"},
        :myData {:B #object[java.io.BufferedInputStream
                            "0x4606379e"
                            "java.io.BufferedInputStream@4606379e"]}}}

(-> *1 :Item :myData :B .readAllBytes nippy/thaw)

;;; {:hello :world}

jjttjj15:02:15

(`.readAllBytes` i think was only added in a slight more recent java version, maybe 1.9? )

neil.clarke08:02:37

@U064UGEUQ Many thanks, I came right. I needed to send a binary blob which was zlib-compressed JSON; what I did was I shelled out and used pigz (from babashka) and wrapped the console output in (byte-array)