Tips for running Clojure web app on Amazon Beanstalk


If you are using in the app for logging, the following snippet will help you to have proper logs on Amazon Beanstalk.

(alter-var-root #'*logger-factory* (constantly (

For Ring/Compojure projects just put this code somewhere at the top of your web handler file.


I described how to get HTTPS support for Clojure web app deployed on Amazon Beanstalk in the previous post.

Sometimes you need to force HTTPS traffic for everything. So e.x. if user requests page on you want to redirect him on

You can setup proxy to do just that.

I was able to achieve this with a sample ring middleware:

(defn https-url [request-url] (str (str (str (str "https://" (:server-name request-url) ":") "443")) (:uri request-url))) (defn require-https [handler] (fn [request] (if (= (:scheme request) :http) (ring.util.response/redirect (https-url request)) (handler request))))

And then just add require-https middleware to your other middlewares. E.x.:

(def war-handler (-> app (require-https) (wrap-resource "public") (wrap-base-url) (wrap-file-info)))