jeudi 5 février 2015

How to set AWS to proxy to a local fake S3 service using Clojure's Amazonica library?

I have a fake S3 service running locally at the following location:



s3.spurious.localhost


I'm trying to set-up a simple example Clojure script (see below) that creates a bucket using this fake service (instead of trying to create a bucket using a live AWS S3 account).



(ns foo-bar.core
(:use [amazonica.aws.s3])
(:require [amazonica.core :refer [defcredential]]))

(def credentials {:access "development_access"
:secret "development_secret"
:region "eu-west-1"})

(def s3-config {:client-config {:proxy-host "s3.spurious.localhost"
:proxy-port 49154}})

(def cred (defcredential
(:access credentials)
(:secret credentials)
(:region credentials)))

(try
(create-bucket s3-config "test-bucket")
(catch Exception e
(prn (ex->map e))))


The problem with this code is that it doesn't look like it's proxying the request as I get the following error message:



{:error-code "405 Method Not Allowed",
:error-type "Client",
:status-code 405,
:request-id nil,
:service-name "Amazon S3",
:message
"Method Not Allowed (Service: Amazon S3; Status Code: 405; Error Code: 405 Method Not Allowed; Request ID: null)",
:stack-trace
"com.amazonaws.services.s3.model.AmazonS3Exception: Method Not Allowed (Service: Amazon S3; Status Code: 405; Error Co
de: 405 Method Not Allowed; Request ID: null), S3 Extended Request ID: null\n\tat com.amazonaws.http.AmazonHttpClient.h
andleErrorResponse(AmazonHttpClient.java:1077)\n\tat com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpCl
ient.java:725)\n\tat com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:460)\n\tat com.amazonaws.h
ttp.AmazonHttpClient.execute(AmazonHttpClient.java:295)\n\tat com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3C
lient.java:3710)\n\tat com.amazonaws.services.s3.AmazonS3Client.createBucket(AmazonS3Client.java:799)\n\tat com.amazona
ws.services.s3.AmazonS3Client.createBucket(AmazonS3Client.java:724)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.De
legatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.ja
va:483)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.in
voke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorIm
pl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:483)\n\tat clojure.lang.Reflector.invokeMatchingMethod(Re
flector.java:93)\n\tat clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:28)\n\tat amazonica.core$fn_call$fn__
1513.invoke(core.clj:752)\n\tat amazonica.core$intern_function$fn__1532.doInvoke(core.clj:803)\n\tat clojure.lang.RestF
n.invoke(RestFn.java:421)\n\tat spurious_aws_sdk_helper.core$eval2340.invoke(core.clj:33)\n\tat clojure.lang.Compiler.e
val(Compiler.java:6703)\n\tat clojure.lang.Compiler.load(Compiler.java:7130)\n\tat user$eval2323.invoke(form-init6561945354880895749.clj:1)\n\tat clojure.lang.Compiler.eval(Compiler.java:6703)\n\tat clojure.lang.Compiler.eval(Compiler.jav
a:6666)\n\tat clojure.core$eval.invoke(core.clj:2927)\n\tat clojure.main$repl$read_eval_print__6625$fn__6628.invoke(mai
n.clj:239)\n\tat clojure.main$repl$read_eval_print__6625.invoke(main.clj:239)\n\tat clojure.main$repl$fn__6634.invoke(m
ain.clj:257)\n\tat clojure.main$repl.doInvoke(main.clj:257)\n\tat clojure.lang.RestFn.invoke(RestFn.java:1523)\n\tat cl
ojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__592.invoke(interruptible_eval.clj:67)\n\tat clojure.lang.A
Fn.applyToHelper(AFn.java:152)\n\tat clojure.lang.AFn.applyTo(AFn.java:144)\n\tat clojure.core$apply.invoke(core.clj:62
4)\n\tat clojure.core$with_bindings_STAR_.doInvoke(core.clj:1862)\n\tat clojure.lang.RestFn.invoke(RestFn.java:425)\n\t
at clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:51)\n\tat clojure.tools.nre
pl.middleware.interruptible_eval$interruptible_eval$fn__634$fn__637.invoke(interruptible_eval.clj:183)\n\tat clojure.to
ols.nrepl.middleware.interruptible_eval$run_next$fn__627.invoke(interruptible_eval.clj:152)\n\tat clojure.lang.AFn.run(
AFn.java:22)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n\tat java.util.conc
urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n\tat java.lang.Thread.run(Thread.java:745)\n"}


Does anyone know what I might be missing?





Aucun commentaire:

Enregistrer un commentaire