在Ruby中(使用Ruby ),您可以执行以下代码来修改特定的AWS配置:
AWS.config(
:use_ssl => false,
:s3_port => 49154,
:s3_endpoint => "s3.spurious.localhost",
:s3_force_path_style => true
)上面的代码片段允许我们使用本地运行的服务来伪造S3 (我们也有其他伪造的端点,比如SQS和DynamoDB,但是为了提供一个简单的简化示例,我省略了它们)。
但是如何在Clojure中使用亚马逊河来实现这一点呢?似乎没有一个直接的config函数。
自述文件建议您使用:环境变量、、~/.aws/credentials或EC2元数据服务提供的凭据。
这些都不符合我们的要求。
但是,自述文件还建议您可以提前调用(defcredential)并将设置映射传递给它(参见下面的示例--由于错误Unable to resolve symbol: defcredential而无法工作)。
另外,在下面的示例脚本中,我尝试使用一个特定的S3函数,并将我的配置细节作为第一个参数传递(正如Amazonica的自述文件所建议的那样,您可以这样做--但这失败了,因为它试图发出HTTP请求,而我没有连接到internet,因此我可以告诉它,它没有使用我们试图指向的本地运行的假S3服务)。
(ns foo-bar.core
(:use [amazonica.aws.s3]))
(def cred {:access-key "development_access"
:secret-key "development_secret"
:endpoint "eu-west-1"
:s3-endpoint "s3.spurious.localhost"
:s3-port 49154
:client-config {:s3-endpoint "s3.spurious.localhost" :s3-port 49154}})
(defcredential cred) ; ERROR:
; Unable to resolve symbol: defcredential
; Amazonica suggests all functions can except first arg
; which can be used as the credentials for the function
; I don't like it, but failing the use of defcredential I needed to try something
(create-bucket cred "testing") ; ERROR:
; Unable to execute HTTP request: testing.s3-eu-west-1.amazonaws.com发布于 2015-02-04 20:41:14
defcredential来自amazonica.core命名空间。请参阅这里
您需要在require声明中对其进行ns声明
(ns foo-bar.core
(:use [amazonica.aws.s3])
(:require [amazonica.core :refer [defcredential]))至于在客户端函数(create-bucket)中指定凭据,您希望在函数调用中指定凭据时设置:endpoint而不是:s3_endpoint。参见第一个示例这里和amazonica.core/keys->cred
https://stackoverflow.com/questions/28329014
复制相似问题