Automate RabbitMQ configuration in Amazon MQ
Yogesh Bhatia and Afroz Khan, Amazon Web Services
Summary
Amazon MQ
You can use this pattern to configure any RabbitMQ cluster. All it requires is connectivity to the cluster. Although there are many other ways to manage RabbitMQ configurations, this solution creates entire application configurations in one step, so you can manage queues and other details easily.
Prerequisites and limitations
Prerequisites
AWS Command Line Interface (AWS CLI) installed and configured
to point to your AWS account Ansible installed, so you can run playbooks to create the configuration
rabbitmqadmin installed (for instructions, see the RabbitMQ documentation
) A RabbitMQ cluster in Amazon MQ, created with healthy Amazon CloudWatch metrics
Additional requirements
Make sure to create the configurations for virtual hosts and users separately and not as part of JSON.
Make sure that the configuration JSON is part of the repository and is version-controlled.
The version of the rabbitmqadmin CLI must be the same as the version of the RabbitMQ server, so the best option is to download the CLI from the RabbitMQ console.
As part of the pipeline, make sure that JSON syntax is validated before each run.
Product versions
AWS CLI version 2.0
Ansible version 2.9.13
rabbitmqadmin version 3.9.13 (must be the same as the RabbitMQ server version)
Architecture
Source technology stack
An RabbitMQ cluster running on an existing on-premises virtual machine (VM) or a Kubernetes cluster (on premises or in the cloud)
Target technology stack
Automated RabbitMQ configurations on Amazon MQ for RabbitMQ
Target architecture
There are many ways to configure RabbitMQ. This pattern uses the import configuration functionality, where a single JSON file contains all the configurations. This file applies all settings and can be managed by a version-control system such as Bitbucket or Git. This pattern uses Ansible to implement the configuration through the rabbitmqadmin CLI.

Tools
AWS services
Amazon MQ
is a managed message broker service that makes it easy to set up and operate message brokers in the cloud. AWS CloudFormation
helps you set up your AWS infrastructure and speed up cloud provisioning with infrastructure as code. AWS CLI
enables you to interact with AWS services by using commands in a command-line shell.
Other tools
rabbitmqadmin
is a command-line tool for the RabbitMQ HTTP-based API. It is used to manage and monitor RabbitMQ nodes and clusters. Ansible
is an open-source tool for automating applications and IT infrastructure.
Code repository
The JSON configuration file used in this pattern and a sample Ansible playbook are provided in the attachment.
Epics
| Task | Description | Skills required |
|---|---|---|
Create a RabbitMQ cluster on AWS. | If you don't already have a RabbitMQ cluster, you can use AWS CloudFormation | General AWS, Ansible |
| Task | Description | Skills required |
|---|---|---|
Create a properties file. | Download the JSON configuration file (
These configurations are performed under the root (/) virtual host, as required by rabbitmqadmin. | JSON |
Retrieve the details of the Amazon MQ for RabbitMQ infrastructure. | Retrieve the following details for the RabbitMQ infrastructure on AWS:
You can use the AWS Management Console or the AWS CLI to retrieve this information. These details enable the Ansible playbook to connect to your AWS account and use the RabbitMQ cluster to run commands. ImportantThe computer that runs the Ansible playbook must be able to access your AWS account, and AWS CLI must already be configured, as described in the Prerequisites section. | General AWS |
Create the | Create the
| Ansible |
Create an Ansible playbook. | For a sample playbook, see Follow best practices for Ansible playbooks, such as securing passwords. Use Ansible Vault for password encryption, and retrieve the RabbitMQ password from the encrypted file. | Ansible |
| Task | Description | Skills required |
|---|---|---|
Run the playbook. | Run the Ansible playbook that you created in the previous epic.
You can verify the new configurations on the RabbitMQ console. | General AWS, RabbitMQ, Ansible |
Related resources
Migrating from RabbitMQ to Amazon MQ
(AWS blog post) Management Command Line Tool
(RabbitMQ documentation) Create or delete an AWS CloudFormation stack
(Ansible documentation) Migrating message driven applications to Amazon MQ for RabbitMQ
(AWS blog post)
Attachments
To access additional content that is associated with this document, unzip the following file: attachment.zip