aws

http://status.aws.amazon.com/ https://www.expeditedssl.com/aws-in-plain-english
2020-02-26T06:12:33.043100Z

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?

2020-02-26T14:14:34.043600Z

@mbbaldwin what is the output of invoking save-stuff? Also, what is the metadata of that output? (meta (save-stuff)).

2020-02-26T15:51:14.044500Z

@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"]}}

2020-02-26T15:54:07.044700Z

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.

2020-02-26T16:19:06.044900Z

I tried BatchWriteItem with a missing attribute and got back error information.

2020-02-26T16:23:53.045100Z

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.)

2020-02-26T16:40:26.045300Z

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.

2020-02-26T16:52:16.045700Z

Correct. I'm calling it from AWS Lambda, but I'm still expecting something.

2020-02-26T16:55:56.046Z

Please submit an issue for this, and include all the dependency information, etc.

2020-02-26T16:58:42.046200Z

Okay, will do when I'm done with work or during lunch.

👍 1
2020-02-26T17:05:52.046500Z

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"}}]}}}
...

2020-02-26T17:09:37.047Z

That's json from examples from AWS. In aws-api, keys like "L" need to be keywords like :L .

2020-02-26T17:17:15.047200Z

Oh, okay. That thought that was "L" for "List". Yes that helps.

👍 1
2020-02-26T21:25:21.047800Z

Thx

2020-02-26T21:26:27.048Z

No, thank you! 🙂