aws

http://status.aws.amazon.com/ https://www.expeditedssl.com/aws-in-plain-english
grounded_sage 2020-02-03T08:32:53.037800Z

I am doing a :PutObject as described here. https://github.com/cognitect-labs/aws-api/blob/master/examples/s3_examples.clj#L58 Though I would like to see the response I get back to confirm that there was no errors. I can see this in the readme but don’t understand how I use it. https://github.com/cognitect-labs/aws-api/blob/master/examples/s3_examples.clj#L58

2020-02-03T17:46:51.039400Z

The response is in the metadata of the return of invoke (used here in the same example file: https://github.com/cognitect-labs/aws-api/blob/5cad085173df0ab48d64823b8a9692b73a3b4ab7/examples/s3_examples.clj#L47)

2020-02-03T17:48:02.039900Z

@grounded_sage ^^

grounded_sage 2020-02-03T18:19:49.040400Z

But that is only for the repl @dchelimsky

chrisulloa 2020-02-03T18:22:22.041500Z

^

(meta (aws/invoke client op))

chrisulloa 2020-02-03T18:22:54.042100Z

I think you’ll find an :http-response key in the meta where you can check the status code

✅ 1
grounded_sage 2020-02-03T19:12:57.043100Z

ah! makes total sense.

ghadi 2020-02-03T19:14:28.044200Z

In general you don’t have to do that

ghadi 2020-02-03T19:14:45.045100Z

Responses return maps, which may include a cognitect/anomaly

grounded_sage 2020-02-03T19:14:46.045200Z

Realised I shared the same links. Was meaning to reference this in the readme. (-> client aws/ops op :response) So I thought there must be some key I can use to get the response. https://github.com/cognitect-labs/aws-api#responses-success-failure

ghadi 2020-02-03T19:15:00.046Z

If you see an anomaly, it means something failed

grounded_sage 2020-02-03T19:15:05.046200Z

How do I get that map?

ghadi 2020-02-03T19:15:22.046800Z

It’s the return value of invoke

grounded_sage 2020-02-03T19:16:22.047500Z

I ended up doing this… (-> (S3-writer! file-path id (:body response)) (contains? :ETag))

grounded_sage 2020-02-03T19:16:34.047800Z

because I couldn’t get a map back

ghadi 2020-02-03T19:17:07.048200Z

What do you mean you couldn’t get a map back?

grounded_sage 2020-02-03T19:17:43.048700Z

Give me a sec. Was about to go home. Will boot up quick and see if I can try what you are saying.

grounded_sage 2020-02-03T19:19:37.049500Z

Doing this in the repl (S3-writer! "/test/" "hello.txt" (.getBytes "Oh hai!")) Returns an {:ETag "\".........\""}

grounded_sage 2020-02-03T19:20:25.050300Z

This is how S3-writer! is defined.

(defn S3-writer!
  [file-path file-name data]
  (aws/invoke s3 {:op :PutObject :request {:Bucket bucket-name
                                           :Key (str partner-folder-name file-path file-name)
                                           :Body data}}))

ghadi 2020-02-03T19:23:25.050700Z

(aws/doc s3client :PutObject) ->

-------------------------
Response

{:RequestCharged [:one-of ["requester"]],
 :ETag string,
 :SSECustomerKeyMD5 string,
 :SSEKMSEncryptionContext string,
 :ServerSideEncryption [:one-of ["AES256" "aws:kms"]],
 :SSECustomerAlgorithm string,
 :SSEKMSKeyId string,
 :Expiration string,
 :VersionId string}

ghadi 2020-02-03T19:23:48.051300Z

if it doesn't return a subset of that stuff directly, there's a bug

ghadi 2020-02-03T19:28:02.052300Z

if the map has a key :cognitect.anomalies/category, that means something has gone wrong

grounded_sage 2020-02-03T20:32:37.054800Z

When I run this from the S3 examples aws-api/examples/s3_examples.clj

(aws/invoke s3 {:op :PutObject :request {:Bucket bucket-name :Key "hello.txt"
                                           :Body (.getBytes "Oh hai!")}}) 
I only get back the :ETag in the repl.

ghadi 2020-02-03T20:33:12.055400Z

map with {:ETag "something"} in it ?

grounded_sage 2020-02-03T20:33:31.055800Z

yes

ghadi 2020-02-03T20:34:41.056900Z

yes, that is correct https://clojurians.slack.com/archives/C09N0H1RB/p1580757828051300

grounded_sage 2020-02-03T20:34:44.057200Z

As referenced above. I ended up piping it into a contains?to check for the tag. But it seems like the wrong way to be checking…

ghadi 2020-02-03T20:35:20.058100Z

personally I would check for the presence of error, instead of the presence of the ETag

ghadi 2020-02-03T20:35:28.058400Z

it depends on what you're doing

ghadi 2020-02-03T20:36:18.059300Z

(defn anomaly? [m] (:cognitect.anomalies/category m))

ghadi 2020-02-03T20:36:23.059500Z

or make a helper ^

ghadi 2020-02-03T20:36:47.060100Z

different inputs to PutObject will produce different subsets of the response spec

ghadi 2020-02-03T20:37:06.060600Z

and I can't say for certain that there's not a request that might not return an ETag at all

grounded_sage 2020-02-03T20:37:52.061Z

Ok thanks. That makes sense.

grounded_sage 2020-02-03T20:42:20.062100Z

Looks more sane wrapping it with anomaly? than what I had.

2020-02-03T20:45:05.062200Z

or (def anomaly? :cognitect.anomalies/category) :)

💯 1