Fork me on GitHub
#holy-lambda
<
2022-05-05
>
Norman Kabir22:05:09

Hello. I'm working with a Clojure app that uses https://github.com/weavejester/integrant. We'd like to deploy it with Holy-Lambda but, based on the examples, it seems that Holy-Lambda expects a handler function? Is it possible to use Integrant/Mount system libraries when deploying with Holy Lambda?

Karol Wójcik03:05:01

A quick answer. Yes.

Karol Wójcik03:05:29

I'll write a longer answer in 2 hours. Just getting up from the :sleeping_accommodation:.

Karol Wójcik07:05:49

;; EXAMPLE 1 - routes outside of the system
(defn AWSLambdaHandler [system request] {:body "Hello" :statusCode 200 :headers {})

(def system (atom nil))

(defn wrap-with-system [handler]
   (fn [request]
     (handler @system request)))

(defn start-system
  []
  (reset! system (sys/start-system {:profile :prod
                                    :base    :lambda})))

(def AWSLambdaHandlerWrapped (wrap-with-system AWSLambdaHandler)
 

(h/entrypoint [#'AWSLambdaHandlerWrapped] {:init-hook start-system})

;; Example 2 - routes inside a system
(defn AWSLambdaHandler [system request] {:body "Hello" :statusCode 200 :headers {})

(defn match-handler-by-request [request] AWSLambdaHandler)

(def system (atom nil))

(defn wrap-with-system []
   (fn [request]
     ((match-handler-by-request @system request) @system request)))

(defn start-system
  []
  (reset! system (sys/start-system {:profile :prod
                                    :base    :lambda})))

(def UnifiedAWSLambdaWrapper (wrap-with-system))

(h/entrypoint [#'UnifiedAWSLambdaWrapper] {:init-hook start-system})

Norman Kabir14:05:57

Amazing! I will try this. Thank you!

Karol Wójcik17:05:33

You are very welcome! Thank you for asking this question.