jschoch

jschoch

Elixir on AWS Lambda

I did a few experiments with running on lambda via exrm because I wanted to avoid writing .js as much as possible. Here is what I found.

  1. the invocation time is slow for 128MB ram, need to make sure you have enough ram since ram and CPU are proportional. 128MB execution time is ~ 2-4 seconds.
  2. permissions are tricky due to the .erlang.cookie and the deployment model. I was only able to get one piece working by setting it to nocookie. You have to be aware that one user puts your files into the container, and your invocation user may be random.
  3. exrm seems to nicely bundle up libs and dependencies for a basic app. No mucking around with LD_LIBRARY_PATH was needed.
  4. deploying less to /var/task (where your zipped files go by default) is the best way to manage permissions. You can’t change these files after they are deployed to this root, but you can deploy a dir with 777 permissions and then chmod it later.
  5. you have to set a HOME env var for each possilbe invoker or erlang will complain. This where .erlang.cookie ends up living and you never know who will invoke. Since erlang.cookie needs something like permistions of 700 or 500 your processes will crash with file access problems.

wondering if others are interested in this

Most Liked

jschoch

jschoch

to add some context here, this means you can run ~100,000 invocations, or phoenix requests, for around $.04 per month in a highly available environment where you can forget about load balancers, patches, ssh keys, etc etc etc.!

jschoch

jschoch

i have a phoenix server running and i’m quite pleased with the results. Base invocation time for starting elixir via escript is around 180ms, but since you can now keep something around, although frozen, for 5 minutes invoking a server on lambda makes much more sense. This saves you a ton of time and expense for lambda.

The below client/server takes between 11 and 20 ms to run with 1024MB ram lambda.

  • 512MB ram seems to be a sweet spot for an app that does nothing, it performed the same as 1024.
  • 256MB was wildly varying between 160 and 200 ms
  • 128MB ram results in ~ 230 ms which frankly isn’t bad compared with native node.

server

def test(conn,_params) do
    json conn, %{worked: :true,conn: inspect(conn)}
  end

client

curl localhost:9080/test

I’ll test with a native node.js http request in a few. should be faster…

mkunikow

mkunikow

Host AWS lamda by your self :slight_smile:

gmolto

gmolto

We recently released the open-source SCAR framework that can run containers out of Docker images on AWS Lambda. We have included an use case to run Elixir code in AWS Lambda, just as a proof of concept of supporting programming languages (and runtime environments) other than those officially supported by AWS Lambda. Just in case you may be interested.

mkunikow

mkunikow

This is not easy task what AWS lamda can do :). You can run the same code on one machine and 1000 machines if needed depends on load. But as developer you don’t care where it runs and how many machines you will need.
The best part you only pay for work AWS lamda do for you , not machines you use for it.
The drawback you need to keep state somewhere else also there is limit how long computation can be executed (I suppose there is 5 minutes)

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

We're in Beta

About us Mission Statement