« Back to Index

Clojure talking to Spurious

View original Gist on GitHub

clojure-spurious-basic.clj

(ns spurious-aws-sdk-helper.core
  (:use [amazonica.aws.s3]))

(def credentials {:access-key "development_access"
                  :secret-key "development_secret"
                  :endpoint "s3.spurious.localhost:49154"
                  :client-config {:protocol "http"}})

(set-s3client-options credentials :path-style-access true)
(create-bucket credentials "testing")

clojure-spurious-extended.clj

(ns spurious-aws-sdk-helper.core
  (:use [amazonica.aws.s3]
        [clojure.pprint :only [print-table]])
  (:require [amazonica.core :refer [defcredential get-credentials ex->map]]
            [clojure.reflect :as r]))

(defn env [name]
  (System/getenv name))

(prn (env "GREETING"))

(def credentials {:access-key "development_access"
                  :secret-key "development_secret"
                  :endpoint "s3.spurious.localhost:49154"
                  :client-config {:protocol "http"}})

; use reflection to see methods on a class
; get-credentials for cred returns BasicAWSCredentials class
(print-table
  (:members
    (r/reflect (get-credentials (defcredential "development_access" "development_secret" "eu-west-1")))))

; display all public functions from a specified namespace and the current namespace
(keys (ns-publics 'amazonica.aws.s3))
(keys (ns-publics *ns*))

(try
  (set-s3client-options credentials :path-style-access true)
  (create-bucket credentials "testing")
  (catch Exception e
    (clojure.pprint/write (ex->map e))))

; to prevent having to pass around `credentials` to every function call we could just call `defcredential` once