Phoenix Cluster in ECS

What is the best way of running a Phoenix server in cluster mode in AWS ECS?

It seems to me like a common problem. I plan to use a libcluster library, but I’m wondering if Phoenix provides anything out of the box.

Also I’m not a devOps, so I don’t completely understand why libcluster offers UDP multicast to 233.252.1.32 for a Gossip strategy… All I found so far are blog posts about creating a lambda that registers new nodes in a cluster, or using some patterns in naming EC2 instances, etc. Any recommendations?

1 Like

Here’s my config block:

config :clove, :cluster_topology,
  main: [
    strategy: ClusterEC2.Strategy.Tags,
    config: [
      # EnvMap is just System.get_env or raise
      ec2_tagname: EnvMap.fetch!("LIBCLUSTER_EC2_TAGNAME"),
      # Should match what's in vm.args / distillery
      app_prefix: "clove",
      ip_type: :private,
      show_debug: false
    ]
  ]

I then pass in aws:cloudformation:stack-id as the ec2 tag name, which is the same for all ec2 instances in the cluster.

Now, there’s an important caveat that I use 1-1 mapping between ec2 instance and running application instance. So, I’m assuming that this will work if it’s 1-many, but I can’t guarantee that.

See ClusterEC2.Strategy.Tags — libcluster_ec2 v0.6.0 for the strategy

2 Likes

Thank you!