This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-27
Channels
- # announcements (14)
- # aws (2)
- # babashka (12)
- # beginners (23)
- # calva (71)
- # cider (37)
- # clj-kondo (47)
- # cljs-dev (3)
- # clojure (55)
- # clojure-brasil (1)
- # clojure-europe (51)
- # clojure-nl (1)
- # clojure-norway (63)
- # clojure-poland (1)
- # clojure-seattle (1)
- # clojure-uk (3)
- # clojurescript (10)
- # conjure (3)
- # cursive (23)
- # data-science (5)
- # emacs (16)
- # events (1)
- # hoplon (16)
- # hyperfiddle (19)
- # introduce-yourself (1)
- # kaocha (5)
- # nyc (1)
- # portal (31)
- # practicalli (2)
- # reitit (3)
- # releases (4)
- # sci (28)
- # slack-help (13)
- # sql (4)
- # squint (40)
- # tools-build (25)
- # tools-deps (10)
Hey Folks,
I’m trying to do something that I think is possible but I can’t figure out the correct syntax or find any examples in the docs. Here’s my code. I’m trying to mock out bits of the S3 API in order to write a test. This is just an example to demonstrate my problem. I thought that I can use the client-opts to make the amazon client hit localhost instead of aws. But when I try to put-object
as below, it is trying to coerce the keyword :input-stream
into an object of instance InputStream
. This happens whether or not I wrap the key/input-stream parameters in a map.
(defn s3-app [store]
{"/" {:put (fn [req]
(swap! store assoc (req/path-info req)
(req/body-string req)))
:get (fn [req]
(get @store (req/path-info req)))}})
(let [store (atom {})]
(with-http [(:s3 ports) (s3-app store)]
(let [client-opts {:cred (DefaultAWSCredentialsProviderChain/getInstance)
:endpoint "localhost"
:region "eu-west-2"
:client-config
{:path-style-access-enabled true
:chunked-encoding-disabled false
:accelerate-mode-enabled false
:payload-signing-enabled true
:dualstack-enabled true
:force-global-bucket-access-enabled true}}]
(s3/put-object
client-opts
{:key "foo"
:input-stream (ByteArrayInputStream. (.getBytes "foo"))}))))
All the examples I could find in the amazonica docs/tests that configure client-opts and use put-object
do so with a file instead of an input stream.
Can anyone see what I’m doing wrong? Cheers.I'm not 100% sure what are you trying to do actually - what is running on localhost? :thinking_face: How about this approach: What I did (and still do), is take a different route when testing S3-related code: rather than mock the client lib or even raw HTTP requests, I use https://github.com/minio/minio as part of the local & test setup. It's light-weight enough that it can just sit there running in Docker and do its thing. Then the only part you configure is the endpoint of your S3 client. This has several advantages: • you don't mock anything • you can use the same client to verify what gets written and how it's read • in my experience it's just a simpler setup overall I don't remember if amazonica helps with this, but when using S3 SDK directly, the "endpoint" config key needs to be a full URL and not a hostname, eg.. http://localhost:8080