Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing GeneratePresignedUrlRequest S3 operation #236

Open
onetom opened this issue Apr 11, 2023 · 2 comments
Open

Missing GeneratePresignedUrlRequest S3 operation #236

onetom opened this issue Apr 11, 2023 · 2 comments

Comments

@onetom
Copy link

onetom commented Apr 11, 2023

Dependencies

{:deps {com.cognitect.aws/api       {:mvn/version "0.8.656"}
        com.cognitect.aws/endpoints {:mvn/version "1.1.12.437"}
        com.cognitect.aws/s3        {:mvn/version "825.2.1250.0"}}}

Description with failing test case

clojure -M \
  -e "(use 'cognitect.aws.client.api)" \
  -e "(run! println (keys (ops (client {:api :s3}))))" \
  | grep -i -E 'generate|sign|url'

I was expecting to find this GeneratePresignedUrlRequest operation in the S3 API.

Is it an oversight or it is not an actual HTTP API request, but something being computed locally?

Would it make sense to have an example in the documentation to show how to do this?

@dchelimsky
Copy link
Contributor

There is no http endpoint for this, so It has to be calculated locally, and the algorithm is subtly different from calculating the signatures for all the other 1000s of operations. It's something we've wanted to support, but just haven't had time to do it since it would require a bit of redesign. There is experimental work on the execution-flow branch, but that represents a radical redesign and it's nearly 3 years old now, so it will be a non-trivial effort to extract that work when we get there.

Yes, it would make sense to have an example if we could provide one, but right now there is no means for you to get all the information you'd need to build the request yourself.

This is on our backlog, but it's not going to be resolved in the immediate near term.

@onetom
Copy link
Author

onetom commented Apr 11, 2023

Given com.amazonaws/aws-java-sdk-s3 {:mvn/version "1.12.445"} in deps.edn, the following seems to work:

(ns x
  (:import (java.util Date)
           (java.time Clock Instant)
           (com.amazonaws HttpMethod)
           (com.amazonaws.services.s3 AmazonS3ClientBuilder)
           (com.amazonaws.services.s3.model GeneratePresignedUrlRequest)))


(comment
  (-> (AmazonS3ClientBuilder/standard)
      (.build)
      (.generatePresignedUrl (-> (GeneratePresignedUrlRequest. "<bucket-name>"
                                                               "<object/key>")
                                 (.withMethod HttpMethod/GET)
                                 (.withExpiration (-> (Clock/systemUTC)
                                                      (Instant/now)
                                                      (.plusSeconds 30)
                                                      (Date/from))))))
  )

The problem is, that we would need to duplicate the logic of creating this Java S3 client the same way (same AWS profile & region or other creds provider) we created the cognitect/aws-api client with :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants