Search code examples
dockerrabbitmqamazon-ecs

Amazon ECS w/ RabbitMQ


I'm trying to translate a docker-compose setup that I have locally into an ECS cluster with tasks. My docker-compose setup looks like this:

version: '3'

services:
  rabbit-mq-service:
    image: rabbitmq:3.6-management
    ports:
      - "15672:15672"
      - "5672:5672"
    environment:
      RABBITMQ_DEFAULT_USER: ***
      RABBITMQ_DEFAULT_PASS: ***
  service-a:
    image: service-a:latest
    depends_on:
      - rabbit-mq-service
    restart: on-failure
    command: --spring.profiles.active=docker --spring.rabbitmq.host=rabbit-mq-service
  service-b:
    image: service-b:latest
    depends_on:
      - rabbit-mq-service
    restart: on-failure
    command: --spring.profiles.active=docker --spring.rabbitmq.host=rabbit-mq-service

This is pretty simple stuff, and it works great in Docker. I can run docker-compose up and I get rabbitmq + 2 services, and both services can connect to the rabbit server.

Right now, I can deploy service-a and service-b to an ECS cluster provided that I hard-code the hostname of the rabbit server. This means that I need to have a separate EC2 instance (or something similar) running the rabbit server. I would really like my cluster to have a rabbit server and have my instances be able to connect to it. So far, no luck.

Is it just better to have the Rabbit server be outside the ECS cluster?

Any suggestions?


Solution

  • Two options:

    1. Yes, run the Rabbit server outside the ECS cluster. Since it has persistent state associated with it it's difficult to move between nodes or replicate, so there's not a lot of benefit to managing it in ECS.

    2. Ask AWS to deploy a load balancer in front of RabbitMQ in ECS. You can give that load balancer its own DNS name (via Route 53) or use its default name, but either way you can use that DNS name to refer to RabbitMQ and it will route whichever host(s) are actually running it.