如何使用 Amazonica 库在 Clojure 中更改 AWS.config?
How do you change AWS.config in Clojure using Amazonica library?
在Ruby中(使用Ruby AWS SDK)您可以执行以下代码来修改特定的AWS配置:
AWS.config(
:use_ssl => false,
:s3_port => 49154,
:s3_endpoint => "s3.spurious.localhost",
:s3_force_path_style => true
)
上面的代码片段允许我们使用本地 运行 伪造 S3 的服务(我们还有其他伪造的端点,例如 SQS 和 DynamoDB,但我希望省略它们提供一个简单的简化示例)。
但是如何使用 Amazonica 在 Clojure 中实现这一点?似乎没有直接的 config
函数。
自述文件建议您使用:环境变量、Java 系统属性、~/.aws/credentials
或 EC2 元数据服务提供的凭据。
None其中非常符合我们的要求。
但是,自述文件还建议您可以预先调用 (defcredential)
并将设置映射传递给它(请参见下面的示例 - 由于错误 Unable to resolve symbol: defcredential
而无法正常工作)。
同样在下面的示例脚本中,我尝试使用特定的 S3 函数并将我的配置详细信息作为第一个参数传递(正如 Amazonica 的自述文件建议您可以这样做 - 但失败了,因为它试图创建一个HTTP 请求,但我没有连接到互联网,所以我可以看出它没有使用我们试图定向到的本地 运行 假 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
defcredential
来自 amazonica.core
命名空间。参见 here
您需要在 ns
声明中 require
它
(ns foo-bar.core
(:use [amazonica.aws.s3])
(:require [amazonica.core :refer [defcredential]))
至于在客户端函数 (create-bucket
) 中指定凭据,您希望在函数调用中内联指定凭据时设置 :endpoint
而不是 :s3_endpoint
。看第一个例子here and amazonica.core/keys->cred
在Ruby中(使用Ruby AWS SDK)您可以执行以下代码来修改特定的AWS配置:
AWS.config(
:use_ssl => false,
:s3_port => 49154,
:s3_endpoint => "s3.spurious.localhost",
:s3_force_path_style => true
)
上面的代码片段允许我们使用本地 运行 伪造 S3 的服务(我们还有其他伪造的端点,例如 SQS 和 DynamoDB,但我希望省略它们提供一个简单的简化示例)。
但是如何使用 Amazonica 在 Clojure 中实现这一点?似乎没有直接的 config
函数。
自述文件建议您使用:环境变量、Java 系统属性、~/.aws/credentials
或 EC2 元数据服务提供的凭据。
None其中非常符合我们的要求。
但是,自述文件还建议您可以预先调用 (defcredential)
并将设置映射传递给它(请参见下面的示例 - 由于错误 Unable to resolve symbol: defcredential
而无法正常工作)。
同样在下面的示例脚本中,我尝试使用特定的 S3 函数并将我的配置详细信息作为第一个参数传递(正如 Amazonica 的自述文件建议您可以这样做 - 但失败了,因为它试图创建一个HTTP 请求,但我没有连接到互联网,所以我可以看出它没有使用我们试图定向到的本地 运行 假 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
defcredential
来自 amazonica.core
命名空间。参见 here
您需要在 ns
声明中 require
它
(ns foo-bar.core
(:use [amazonica.aws.s3])
(:require [amazonica.core :refer [defcredential]))
至于在客户端函数 (create-bucket
) 中指定凭据,您希望在函数调用中内联指定凭据时设置 :endpoint
而不是 :s3_endpoint
。看第一个例子here and amazonica.core/keys->cred