Fork me on GitHub
#aws
<
2020-02-03
>
grounded_sage08:02:53

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

dchelimsky17:02:51

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)

grounded_sage18:02:49

But that is only for the repl @dchelimsky

chrisulloa18:02:22

^

(meta (aws/invoke client op))

chrisulloa18:02:54

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

1
grounded_sage19:02:57

ah! makes total sense.

ghadi19:02:28

In general you don’t have to do that

ghadi19:02:45

Responses return maps, which may include a cognitect/anomaly

grounded_sage19:02:46

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

ghadi19:02:00

If you see an anomaly, it means something failed

grounded_sage19:02:05

How do I get that map?

ghadi19:02:22

It’s the return value of invoke

grounded_sage19:02:22

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

grounded_sage19:02:34

because I couldn’t get a map back

ghadi19:02:07

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

grounded_sage19:02:43

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

grounded_sage19:02:37

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

grounded_sage19:02:25

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

ghadi19:02:25

(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}

ghadi19:02:48

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

ghadi19:02:02

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

grounded_sage20:02:37

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.

ghadi20:02:12

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

grounded_sage20:02:44

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…

ghadi20:02:20

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

ghadi20:02:28

it depends on what you're doing

ghadi20:02:18

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

dchelimsky20:02:05

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

💯 1
ghadi20:02:23

or make a helper ^

ghadi20:02:47

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

ghadi20:02:06

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

grounded_sage20:02:52

Ok thanks. That makes sense.

grounded_sage20:02:20

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