Heroku has a great feature called heroku ps:exec
which allows you to connect to running nodes. You can use this command to connect your elixir nodes easily. And debug your nodes like in your network.
Let's start with Procfile
To run a named app at heroku your procfile should specify the app name like:
web: MIX_ENV=prod elixir --sname coolelixirapp -S mix run --no-halt
If you are using Phoenix framework:
web: MIX_ENV=prod elixir --sname coolelixirapp -S mix phx.server
Deploy your app with one of these Procfiles depending on your app type.
On your local:
$ heroku config # list your heroku app configs
$ heroku ps:exec # --dyno=web.1 # will connect you to web1 dyno
Note: heroku ps:exec
command does not export your configs to the heroku bash
shell. So you will need to export them by yourself.
Now you are in Heroku bash
shell for web.1
dyno:
$ # You may need to export env vars which listed in previous 'heroku config' execution.
$ export DATABASE_URL=postgres://username:password@hostname:5432/dbname;
$ export DATABASE_POOL_SIZE=1;
$ # .... Do your all necessary exports
$ MIX_ENV=prod iex --sname coolelixirconsole -S mix # Run a console app
Now you are in Elixir console with app name coolelixirconsole
:
>> iex(coolelixirconsole@hostname)1> Node.ping :"coolelixirapp@hostname"
>>> :pong # We are connected to our running Elixir node from heroku ps:exec console
>> iex(coolelixirconsole@hostname)2> Node.list
>>> [:"coolelixirapp@hostname"] # As expected it is in the list
>> iex(coolelixirconsole@hostname)3> # Now you can tell what to do to your app as in your network.