jfrolich

jfrolich

Did anyone successfully set up ECS using distributed Elixir? I am tackling this right now.

I am especially interested how to connect the nodes. I was thinking it might make sense to write a custom libcluster strategy that fetches the current ip’s connected to the Application Load Balancer. ECS also offers service discovery using DNS, so that might also be a solution (this creates an A record for each node) and there seems to be a DNS strategy already in libcluster.

As far as I know these are the things to be addressed:

  • Setting the node name to: <APPNAME>@<PRIVATE IP>
  • Exposing the Port Mapper Daemon port in the VPC and docker image (4369)
  • Exposing the intra-erlang communication ports (configurable using inet_dist_listen_min, inet_dist_listen_max) in the VPC and the docker image
  • Service discovery (setting up communication between nodes) using a libcluster strategy

Setting the hostname to include the private IP can be done by using curl http://169.254.169.254/latest/meta-data/local-ipv4, not sure yet how to best inject this as a env variable.

Perhaps anyone already has figured some of this out on ECS/EC2? Help really appreciated! Planning to document the results so it’s easier for other to get this up and running. I already have some experience building a very small docker image using releases and multi-stage builds.

Showing Posts 15 to 6

acrolink

acrolink

Does the same applies for Elastic Beanstalk with applications deployed using Docker?

mowings

mowings

So after some investigation, it does look like the A records get removed immediately with the stop requests. It also appears that the application does not get a SIGTERM for quite a while after that – the container remains active all the way through to the end of the DEPROVISIONING state.

The limitation with the number of A records being limited to 8 stands, however. More than that and the cluster will experience lots of random disconnects and reconnects. It is possible that things may eventually stabilze (seems like it should in theory) – I am still looking at this.

mowings

mowings

Thanks for this write-up. However, note that Route53 multi-value DNS will only ever return 8 records maximum. This limits the number of nodes in a cluster using this strategy to 8. Any more than that, and the results returned by the dns query will vary each time, causing libcluster to think nodes are coming and going, and you will see lots of disconnects/reconnects.

There is also a possible issue with the task IPs getting removed from the private namespace zone only after a task has transitioned to the STOPPED state (which seems like a major design flaw), not giving a task being shut down a chance to drain any pending requests and account for the A record TTL. I have not fully investigated this, however.

drewble

drewble

I struggled with this for a week and eventually got it working. The information in this thread is enough to point in the right direction, but there is a big gap between the right direction and a successful deployment.

I’ve written up a fresh guide on deploying distributed Elixir to ECS Fargate tasks with Service Discovery and libcluster’s DNS Polling strategy. Hope it helps save someone some time!

JorisKok

JorisKok

I am using the bridge network mode, with the custom peerage provider for srv records.

 NAME                RESULT OF ATTEMPT
 api@172.31.13.73 true      
 api@172.31.6.233 false     

 LIVE NODES
 api@172.31.13.73 (self)

Not really sure why it won’t connect. Any help is appreciated.

lukaszsamson

lukaszsamson

ElixirLS Core Team

We use a custom Peerage.Provider implementation like

defmodule AwsServiceDiscovery do
  @behaviour Peerage.Provider

  @impl true
  def poll do
    dns_name = Application.fetch_env!(:peerage, :dns_name)
    app_name = Application.fetch_env!(:peerage, :app_name)

    :inet_res.lookup(String.to_charlist(dns_name), :in, :srv)
    |> Enum.flat_map(fn {_priority, _weight, _port, srv_dns_name} ->
      :inet_res.lookup(srv_dns_name, :in, :a)
      |> Enum.map(fn ip ->
        :"#{app_name}@#{:inet.ntoa(ip) |> to_string}"
      end)
    end)
  end
end
quolpr

quolpr

Our tasks are using awsvpc network mode. It has some limits depending on EC2 instance type Elastic network interfaces - Amazon Elastic Compute Cloud . With Fargate you don’t need to think about this limitation

jfrolich

jfrolich OP

I use Fargate, so it uses the A record for service discovery.

troelsim

troelsim

Hey guys, thanks for all the info, it helped me a lot set it up myself.

You’re all running one node per instance, with a fixed port mapping from container to host, right?

AWS doesn’t allow A records in the service registry unless the networkMode of the container is awsvpc (where each container has its own elastic network interface and IP address), I suppose because there could be multiple instances per host, running on different ports. It has to be SRV, which is fine.

The DNSPoll strategy only polls A records by default, so I’m curious about whether you guys had to use a custom resolver like I did, or if there’s a more straightforward way?

jfrolich

jfrolich OP

Yep that’s exactly what we are using as well now. BTW the erlang communication port can be a single port.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews