brendanhay / amazonka

A comprehensive Amazon Web Services SDK for Haskell.
https://amazonka.brendanhay.nz
Other
599 stars 227 forks source link

S3 - Get pre-signed put object URL? #976

Closed jaanisfehling closed 6 months ago

jaanisfehling commented 6 months ago

How can I get a pre-signed put-object URL in amazonka-2.0? I found this snippet for versions <2.0: https://stackoverflow.com/questions/58225056/how-to-get-signed-put-object-url-with-amazonka Relevant AWS Docs: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-s3-presign.html

I am new to Haskell and couldn't find proper documentation anywhere, I guess the documentation are the types, but I could not find a function for this functionality.

endgame commented 6 months ago

The examples have code for pre-signing a s3:getObject call, which might get you started:

https://github.com/brendanhay/amazonka/blob/9c3594073a7787e27f13fa14c936f0fa5cb9f0e8/examples/src/S3.hs#L28-L39

The general presigning interface is discussed in the haddocks: https://hackage.haskell.org/package/amazonka-2.0/docs/Amazonka.html#v:presignURL

I know I've looked at fixes around handling unsigned bodies before (where you don't know what the client is uploading), so everything should work. When you construct your Amazonka.S3.PutObject request to be signed, leave the body empty: that's how it knows to use unsigned payloads.

endgame commented 6 months ago

I'll close this off because I think there should be enough information to get you unstuck. If not, please reopen.

jaanisfehling commented 6 months ago

Thank you very much, works like a charm. Took me a day to integrate into my code, because I didnt know how to get rid of the IO Monad. Turns out you cannot, but I found a way to convert the monad another monad that fits into my code (I learned a lot about monads in the process).