I have be been wondering how to do intrastructure as code in Clojure. So I made an example for it using AWS CDK.
You can find the example in this repo https://github.com/WarFox/clojure-cdk-example
The example can deploy an SNS Topic, SQS Queue and subscription. There is also a basic test setup in the example. One of the benefits of using CDK is that we get define tests for our infrastructure in the chosen language.
The hardest part in using CDK with Clojure is defining the dependency betweeen the app, stacks and resources. In Java it naturally managed by class inheritance and composition; an app is composed by stacks and stacks are composed by resources.
In Clojure with Java Interop, we can manage such dependency using something like Integrant. Integrant lets you define dependency between componets of your system using a simlpe data structure.
The following is the integrant configuration used in the example app.
Integrant will take care of initiating the components based on the configuration
pass the components for
To make the setup work with
CDK, we also need to configure it in
I also have the following alias is
deps.edn to make it work.
Checkout the example here and give it a star if you like https://github.com/WarFox/clojure-cdk-example.
You can run
cdk synth and
cdk deploy after checkout.
I am not stongly recommending you to use Clojure with CDK. Probably
is the best language natively supported by the CDK team. However, if you like to
leverage Clojure's simplicity in CDK then go ahead give it a try.
There are several other ways to manage infrastructure using Clojure. MarketSplash has a good article about Clojure's role in devops. This has many examples for using Clojure for your infrastructure needs.
Here is another article about using Clojure with CDK https://matthewdowney.github.io/aws-cdk-clojure-cloudformation.html
Hope this example gives a reference for your next CDK project!