holy-lambda

Norman Kabir 2022-05-05T22:03:09.530139Z

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ójcik 2022-05-06T03:34:01.996369Z

A quick answer. Yes.

Karol Wójcik 2022-05-06T03:43:29.371609Z

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

Karol Wójcik 2022-05-06T07:07:49.228109Z

;; 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 Kabir 2022-05-06T14:08:57.448609Z

Amazing! I will try this. Thank you!

Karol Wójcik 2022-05-06T17:09:33.247609Z

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