mercredi 4 février 2015

How do you change AWS.config in Clojure using Amazonica library?

In Ruby (using the Ruby AWS SDK) you can execute the following code to modify specific AWS configurations:



AWS.config(
:use_ssl => false,
:s3_port => 49154,
:s3_endpoint => "s3.spurious.localhost",
:s3_force_path_style => true
)


The above snippet of code allows us to use a locally running service that fakes S3 (we've got other faked endpoints as well, such as SQS and DynamoDB but I've omitted them in the hope of providing a simple reduced example).


But how can this be achieved in Clojure using Amazonica? There doesn't appear to be a straight forward config function.


The README suggests you either use: environment variables, Java System Properties, ~/.aws/credentials or credentials provided by the EC2 metadata service.


None of which really fit our requirements.


BUT, the README also suggests that you can call (defcredential) up front and pass it a map of settings (see below example - which doesn't work because of an error Unable to resolve symbol: defcredential).


Also in the following example script I've tried using a specific S3 function and passing my configuration details as the first argument (as the README for Amazonica suggests you can do that - but that fails because it tried to make an HTTP request whilst I wasn't connected to the internet and so I could tell it wasn't using the locally running fake S3 service we're trying to direct to).



(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




Aucun commentaire:

Enregistrer un commentaire