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
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)
But that is only for the repl @dchelimsky
^
(meta (aws/invoke client op))
I think you’ll find an :http-response key in the meta where you can check the status code
ah! makes total sense.
In general you don’t have to do that
Responses return maps, which may include a cognitect/anomaly
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
If you see an anomaly, it means something failed
How do I get that map?
It’s the return value of invoke
I ended up doing this… (-> (S3-writer! file-path id (:body response)) (contains? :ETag))
because I couldn’t get a map back
What do you mean you couldn’t get a map back?
Give me a sec. Was about to go home. Will boot up quick and see if I can try what you are saying.
Doing this in the repl (S3-writer! "/test/" "hello.txt" (.getBytes "Oh hai!"))
Returns an {:ETag "\".........\""}
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}}))
(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}
if it doesn't return a subset of that stuff directly, there's a bug
if the map has a key :cognitect.anomalies/category
, that means something has gone wrong
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.map with {:ETag "something"}
in it ?
yes
yes, that is correct https://clojurians.slack.com/archives/C09N0H1RB/p1580757828051300
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…
personally I would check for the presence of error, instead of the presence of the ETag
it depends on what you're doing
(defn anomaly? [m] (:cognitect.anomalies/category m))
or make a helper ^
different inputs to PutObject will produce different subsets of the response spec
and I can't say for certain that there's not a request that might not return an ETag at all
Ok thanks. That makes sense.
Looks more sane wrapping it with anomaly?
than what I had.
or (def anomaly? :cognitect.anomalies/category)
:)