Go back
Ulam Labs Logo

RabbitMQ Cluster With Terraform On AWS

Software Development

RabbitMQ Cluster With Terraform On AWS

July 31, 2017
, by 
Konrad Rotkiewicz

Creating RabbitMQ cluster is tricky. It is easy to do manually and hard if you’d like to automate it.

TL;DR Use this Terraform configuration to create RabbitMQ cluster in less than 5 minutes.

The simplest cluster requires 2 nodes and a load balancer. In AWS we are going to use ELB as a load balancer and put nodes in Auto Scaling group, so that if a node goes down (or became unhealthy) it will be replaced by a new one.

Our setup will be:


Using Terraform we can create Launch Configuration, Auto Scaling group and ELB. This is our ELB configuration:

What about nodes ? We use cloud-init to initialize a node and in there we configure RabbitMQ to run in Docker.

To find out what are the other nodes in the cluster we prepared a bash script that query nodes in our Auto Scaling group:

And then a script to join to these nodes:

The tricky part here is that to join a cluster, you have to stop the node first. So there is a chance that other node could also be stopped as well. To mitigate this problem we set sleep for some random amount of seconds before stopping the server Also, in case of errors, we perform sane amount of retries.

Using this Terraform configuration we successfully deployed many RabbitMQ clusters with up to 4 nodes.

Leave a comment if you find this useful or a question in case of troubles. Cheers!

Have questions regarding developing
your project?

Get in touch

Latest stories

Read more stories about Ulam Labs and crypto-space wrote by our specialists and engineers.

Legacy APIs and How To Integrate Them with Django, Celery, and A Lil' Bit of Tenacity

How do you envision premedical IT services?They should be reliable. After all, they support the medical sector, right? And they are reliable. Since I've started working for Medishout

Read more

FinTech Consulting 101: How To Get The Most Out of It?

In spite of the COVID-19 pandemic slowing down the global economy, one particular industry has been making remarkable progress. This is the Fintech which is expanding exponentially...

Read more

Managing State In React Apps: Redux vs React Context

When creating a React application, eventually we will come across a point where we need to pass some data from one component to another. And what is the simplest way to do this?...

Read more