Surprise⌠it doesnât, but alas, the Clojure community heroes came to the rescue. It turns out that I am not the only person who finds it important to have good tooling available in Babashka.
I was kindly pointed in the direction of awyeah-api (aka. aws-api
for Babashka), which creates a client that is compatible with Cognitectâs AWS API client.
â Thank you â¤ď¸
By outsourcing âproviding credentials and configâ using an external client, I simplified the code by having less responsibility (still less than 250 lines of code with more features). Also, these clients are battle-tested (or at least âbetter testedâ), compared to my old sad excuse for a âclient implementationâ. On top, the external clients are faster because they cache credentials and config, avoiding re-reading files from disk and environment variables.
But âHow does using the library look?â you ask.
(require '[com.grzm.awyeah.client.api :as aws]
'[aws-simple-sign.core :as aws-sign])
(def client
(aws/client {:api :s3}))
(aws-sign/generate-presigned-url client "somebucket" "someobject.txt" {})
; "https://somebucket.s3.us-east-1.amazonaws.com/someobject.txt?X-Amz-Security-Token=FwoG..."
It has been tested both using an AWS S3 bucket and locally using MinIO, a Cloud storage server compatible with Amazon S3. MinIO has an excellent Docker image, perfect for testing S3 code in a local setup.
(def client
(aws/client {:api :s3
:endpoint-override {:protocol :http
:hostname "localhost"
:port 9000}}))
(aws-sign/generate-presigned-url client "somebucket" "someobject.txt"
{:path-style true})
; http://localhost:9000/somebucket/someobject.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&..."
According to âUse endpoints in the AWS CLIâ documentation, endpoints can be provided by either using the environment variables AWS_ENDPOINT_URL
and AWS_ENDPOINT_URL_S3
or using the endpoint_url
setting within a profile - BUT neither client libraries pick up on that. đ¤ˇ
For now use :endpoint-override
as shown above.
I would love to get some feedback from people using this on non-Amazon clouds like Google, Azure and Digital Ocean among others. There are lots of things I still donât understand about all the different scenarios in which the S3 technology is used.
On a final note, support for upload URLs is still on the TODO list, but I suspect (hope?) it wouldnât be too hard to crack.
I really hope this will be useful for others than me.
S3 presigned URL generation with Babashka
Š 2024 by Jacob Emcken is licensed under CC BY-SA 4.0