I'm trying to save multiple records to DynamoDB using cognitect-labs/aws-api (as per example found here https://github.com/cognitect-labs/aws-api/blob/master/examples/dynamodb_examples.clj) but while it seems that it's set up the same as the examples I'm clearly doing something wrong. The image shows "user errors" which are described as 400
errors due to poor formatting. My code is similar to this:
(def ddb (aws/client {:api :dynamodb}))
(defn save-stuff []
(aws/invoke ddb {:op :BatchWriteItem,
:request
{:RequestItems
{"twitter-sentiment"
[{"PutRequest"
{"Item"
{"twitter-id" {:S "1232539310127140864"}, "lang" {:S "en"}}}}
{"PutRequest"
{"Item"
{"twitter-id" {:S "1232539306297823232"}, "lang" {:S "en"}}}}]}}}
Any idea what I'm doing wrong?@mbbaldwin what is the output of invoking save-stuff
? Also, what is the metadata of that output? (meta (save-stuff))
.
@dchelimsky Oh sorry I should have mentioned that (late night with a sick kid put it out of my mind). There is no console output. The metadata for the fn is:
{:http-request
{:request-method :post,
:scheme :https,
:server-port 443,
:uri "/",
:headers
{"x-amz-date" "20200226T154816Z",
"x-amz-target" "DynamoDB_20120810.BatchWriteItem",
"content-type" "application/x-amz-json-1.0",
"host" "<http://dynamodb.us-east-1.amazonaws.com|dynamodb.us-east-1.amazonaws.com>",
"x-amz-security-token" [really long token],
"authorization" [authorization-stuff]},
:body
#object[java.nio.HeapByteBuffer 0x587a1cfb "java.nio.HeapByteBuffer[pos=0 lim=46 cap=46]"],
:server-name "<http://dynamodb.us-east-1.amazonaws.com|dynamodb.us-east-1.amazonaws.com>"},
:http-response
{:status 400,
:headers
{"server" "Server",
"connection" "keep-alive",
"x-amzn-requestid"
"KTLRO9VJ2L47DJAV84A3QT7UDFVV4KQNSO5AEMVJF66Q9ASUAAJG",
"x-amz-crc32" "3101795386",
"content-length" "179",
"date" "Wed, 26 Feb 2020 15:48:16 GMT",
"content-type" "application/x-amz-json-1.0"},
:body
#object[<http://java.io|java.io>.BufferedInputStream 0x5fa23c "<http://java.io|java.io>.BufferedInputStream@5fa23c"]}}
FYI: I'm also not setting up the tables in the code, and the lang
field doesn't exist on the table yet. Not sure if that's pertinent or not.
I tried BatchWriteItem
with a missing attribute and got back error information.
A missing attribute? Since DynamoDB is a schema-less db, shouldn't it not matter what objects you put in it (as long as it has the required id
specified for the table)? (Meaning you can add attributes or leave them off as needed.)
If I comment out the "Subject" attribute when creating the "Thread" table in the ddb example (https://github.com/cognitect-labs/aws-api/blob/2e4bca75d51e9557608071d061db985e38dc005d/examples/dynamodb_examples.clj#L44), then I get
{:__type "com.amazon.coral.validate#ValidationException",
:message "Provided list of item keys contains duplicates",
:cognitect.anomalies/category :cognitect.anomalies/incorrect}
back from WriteBatchItem
. Not clear on why that is yet, but the point is that I'm getting some feedback and you're saying you're not getting any.Correct. I'm calling it from AWS Lambda, but I'm still expecting something.
Please submit an issue for this, and include all the dependency information, etc.
Okay, will do when I'm done with work or during lunch.
An unrelated question I had that I couldn't find any examples for, when adding a sub-map is the proper syntax to add a vector of attribute maps? Like this:
...
{"PutRequest" {"Item" {"id" {:S id}
"x" {:M [{:height {:N "16"}} {:name {:S "John"}}]}}}
...
Does this help? https://github.com/cognitect-labs/aws-api/blob/master/examples/resources/dynamodb/Thread.json#L30-L42
That's json from examples from AWS. In aws-api, keys like "L" need to be keywords like :L
.
Oh, okay. That thought that was "L" for "List". Yes that helps.
Thx
No, thank you! 🙂