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.
- 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.
wondering if others are interested in this
Most Liked
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
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
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









