【发布时间】:2015-04-05 02:15:32
【问题描述】:
我是一名迁移到 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) 添加到主机名上。我需要 SDK 使用路径样式与我们的本地(假)S3 服务 (s3.spurious.localhost:49154) 通信。
例如喜欢http://s3.spurious.localhost:49154/testing
我认为这是因为我没有正确翻译 Java 代码...
(amazonica.aws.s3/set-s3client-options {:path-style-access true})
...这是将映射传递给set-s3client-options,而不是它应该传递的映射,这是传递在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
(. (com.amazonaws.services.s3.S3ClientOptions.) setPathStyleAccess true))
(create-bucket credentials "testing")
(catch Exception e
(clojure.pprint/write (ex->map e))))
【问题讨论】:
标签: amazon-web-services clojure amazonica