Running a Clojure application on AWS Elastic Beanstalk with Clojure CLI tools


So I wanted to run my Clojure application in Amazon Elastic Beanstalk without going through the trouble of building JARs etc.

I had some issues with file permissions etc so I’m just writing here what needed to be done for others (and Google) to find. I assume you have already created an application and a Java environment based on Amazon Linux and Java 8, and you have successfully deployed the Sample application, and also that you have done the eb init dance to setup the Elastic Beanstalk CLI on your machine and project.

  1. Setup your application so that it runs via the clojure command like clojure -m myapp.main
  2. Ensure that you read the HTTP port with (System/getenv "PORT") (the default port in EB is 5000), and that you write logs etc to STDOUT and STDERR.
  3. Add a Procfile at the root of your project containing:
web: clojure -m myapp.main
  1. Create an .ebextensions directory, and inside it create a file called setup.config (only the extension is relevant, you can name it as you please), containing:
  - option_name: CLJ_CONFIG
    value: /home/webapp/.clojure

    command: |
      curl -O
      chmod +x
      sudo ./

That’s all! You can now do eb deploy (or most probably eb deploy --staged) and you should have a working Clojure HTTP application on Elastic Beanstalk.

Your logs appear at /var/log/web.1.log (stdout) and /var/log/web.1.error.log (stderr).