我是一名迁移到 Clojure 的 Ruby 开发人员,我无法理解如何根据 Clojure 库Amazonica中使用的约定将以下 Java 调用转换为 Clojure 。
AmazonS3 client = new AmazonS3Client(credentials);
client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
我现在的代码是:
(ns spurious-aws-sdk-helper.core
(:use [amazonica.aws.s3]])
(:require [amazonica.core :refer [ex->map]]))
(def credentials {:access-key "development_access"
:secret-key "development_secret"
:endpoint "s3.spurious.localhost:49154"
:client-config {:protocol "http"}})
(try
(amazonica.aws.s3/set-s3client-options {:path-style-access true})
(create-bucket credentials "testing")
(catch Exception e
(clojure.pprint/write (ex->map e))))
但我收到以下错误:
com.amazonaws.http.AmazonHttpClient executeHelper
INFO: Unable to execute HTTP request: testing.s3.spurious.localhost
java.net.UnknownHostException: testing.s3.spurious.localhost
这看起来不正确,因为它将存储桶名称 ( testing
) 添加到主机名上。我需要 SDKs3.spurious.localhost:49154
使用路径样式与我们的本地(假)S3 服务()通信。
例如喜欢http://s3.spurious.localhost:49154/testing
我认为这是因为我没有正确翻译 Java 代码......
(amazonica.aws.s3/set-s3client-options {:path-style-access true})
...这是传递一个映射set-s3client-options
而不是它应该是什么,这是传递调用withPathStyleAccess(true)
一个新实例的结果S3ClientOptions
。但我不知道如何在这里做到这一点?
任何帮助将不胜感激。
更新
这是代码的最新版本(仍然不起作用)...
(ns spurious-aws-sdk-helper.core
(:use [amazonica.aws.s3])
(:require [amazonica.core :refer [ex->map]]))
(def credentials {:access-key "development_access"
:secret-key "development_secret"
:endpoint "s3.spurious.localhost:49154"
:client-config {:protocol "http"}})
(try
(amazonica.aws.s3/set-s3client-options
(. (com.amazonaws.services.s3.S3ClientOptions.) setPathStyleAccess true))
(create-bucket credentials "testing")
(catch Exception e
(clojure.pprint/write (ex->map e))))