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.
- Setup your application so that it runs via the clojure command like
clojure -m myapp.main
- 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. - Add a
Procfile
at the root of your project containing:
web: clojure -m myapp.main
- Create an
.ebextensions
directory, and inside it create a file calledsetup.config
(only the extension is relevant, you can name it as you please), containing:
option_settings:
- option_name: CLJ_CONFIG
value: /home/webapp/.clojure
commands:
01_install_clojure:
command: |
curl -O https://download.clojure.org/install/linux-install-1.10.0.442.sh
chmod +x linux-install-1.10.0.442.sh
sudo ./linux-install-1.10.0.442.sh
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).