Created
June 5, 2016 17:16
-
-
Save mrmcc3/446fac0bbc29510ccd5768b014a06842 to your computer and use it in GitHub Desktop.
include aero config from s3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:remote #include "s3://aero-s3-example/secrets.edn" | |
:local #include "../project.clj"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns aero-s3-example.core | |
(:require [aero.core :as aero]) | |
(:import [com.amazonaws.regions Regions Region] | |
[com.amazonaws.auth DefaultAWSCredentialsProviderChain] | |
[com.amazonaws.services.s3 AmazonS3Client AmazonS3URI] | |
[com.amazonaws.services.s3.model GetObjectRequest])) | |
(defn s3-uri [s] | |
(try | |
(let [uri (AmazonS3URI. s)] | |
{:bucket (.getBucket uri) | |
:key (.getKey uri) | |
:region (.getRegion uri) | |
:version (.getVersionId uri)}) | |
(catch Exception _ nil))) | |
(defn aws-region [region] | |
(-> region Regions/fromName Region/getRegion)) | |
(def s3-client | |
(-> (AmazonS3Client. #_(DefaultAWSCredentialsProviderChain.)) | |
(.withRegion (aws-region "ap-southeast-2")))) | |
(defn s3-resolver [source include] | |
(if-let [{:keys [bucket key region version]} (s3-uri include)] | |
(let [req (GetObjectRequest. bucket key version)] | |
(when region | |
(.setRegion s3-client (aws-region region))) | |
(-> s3-client (.getObject req) .getObjectContent)) | |
(aero/relative-resolver source include))) | |
(comment | |
(aero/read-config "resources/config.edn" {:resolver s3-resolver}) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject aero-s3-example "0.1.0-SNAPSHOT" | |
:dependencies [[org.clojure/clojure "1.8.0"] | |
[com.amazonaws/aws-java-sdk-s3 "1.11.6"] | |
[aero "1.0.0-beta5"]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment