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.
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.
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.
exrm seems to nicely bundle up libs and dependencies for a basic app. No mucking around with LD_LIBRARY_PATH was needed.
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.
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.
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…
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.!
Maybe someone can explain to me because I don’t get it.
Why use AWS lambda when Elixir can just start a supervised task and perform your work for you? What kind of work would AWS lambda be better for where a lightweight process doesn’t fit better?
i suppose the biggest benefit for me is that the server goes away and I can continue to use elixir.
Let’s say I want to process a file. Old way: i setup a server and let it run for ever waiting for some request. New way. someone dumps a file in an S3 bucket which generates an event that starts my lambda function and processes the file. I’ve just removed all the muck associated with maintaining a server (or 2 or 3 if you need HA) for a trivial task. I really don’t want to think about certs and load balancers, and patches, and security 0days, not to mention the expense of having 2 of everything. Lambda is essentially devops in a box, scaling, HA, all taken care of for literally pennies.
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)
First I am not convinced that elixir/erlang is good for short running process which aws lamda is.
There are many workarounds to run not supported languages:
Can you elaborate on the downsides? What makes elixir not well suited for lambda? If you boot the erlang VM in the node.js module initialization it is plenty fast and you can avoid the VM boot tax. I can get < 10ms response times with my prototype.
The upsides are that you can use elixir’s great syntax, and you don’t have to pay for a server waiting around for stuff to do for spiky workloads or very low transaction rates. the HA of Lambda is a big win not to mention avoiding all the hassle of updating/patching another set of server’s operating systems.
It would be cool to have Elixir working on Lambda because of cost saving, but the high available nature of Erlang does not make it best fit for this architecture.