Skip to content

Instantly share code, notes, and snippets.

@d11wtq
Last active August 29, 2015 14:16
Show Gist options
  • Save d11wtq/702f272ff0234c83f88a to your computer and use it in GitHub Desktop.
Save d11wtq/702f272ff0234c83f88a to your computer and use it in GitHub Desktop.
(ns example.factory.aws.cloudformation)
(defn apply-stack-fn
[create-fn update-fn]
(fn apply-stack
[payload]
(try
(create-fn payload)
(catch AlreadyExistsException e
(update-fn payload)))))
(defn expand-params
[params-hash]
(map
(fn [key value]
(zipmap [:parameter-key :parameter-value]
[key value]))
params))
(defn deploy-stack-fn
[apply-fn]
(fn deploy-stack
[stack-name template-hash params-hash]
(apply-fn :stack-name stack-name
:template-body (json/write-str template-hash)
:parameters (expand-params params-hash))))
(ns example.aws.cloudformation
(:require [example.factory.aws.cloudformation :as factory]
[amazonica.aws.cloudformation :as cloudformation])) ; side-effecty AWS SDK
(def apply-stack
(factory/apply-stack-fn cloudformation/create-stack
cloudformation/update-stack))
(def deploy-stack
(factory/deploy-stack-fn apply-stack))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment