Replies: 1 comment 8 replies
-
I made a trial also, using the nodejs14x runtime: https://github.com/viesti/nbb-lambda The gist was to load nbb inside the handler function, since the async import that nbb uses seems to make it hard to load the libraty in a "top level" expression in nodejs, in the way that the default Lambda runtime works (seems that it looks for index.js, so misses index.mjs). I used the Lambda console to then modify the core.cljs code so that it loades the bundled AWS JavaScript library and used functionality from that library. Next thing wouöd be to test the v3 of AWS JS libs, since the nodejs runtimes bundle only v2. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
nbb on AWS Lambda
I wanted to play with idea of having a simple and easy way to run
cljs
code on AWS Lambda. Ideally the goal is that it would be possible to writecljs
code directly in the Lambda console and run it. Another goal is to use existing battle tested runtime code from AWS as much as possible.Approach
nbb
vianpm
cljs
file withnbb
APIFiles
Dockerfile
runtime/bootstrap
This file is originally copied from
/var/runtime/bootstrap
.The only change is that
/var/runtime/index.js
file extension was changed to.mjs
so we can importnbb
.runtime/index.mjs
This file is originally copied from
/var/runtime/index.js
. Since the original code usesrequire
(cjs) andnbb
usesimport
(mjs) I made a quick hack to support both (createRequire
).Instead of using
UserFunction.load
to load userland code and resolve the handler function, I useloadFile
from nbb API to do the same. Here the file and function names are hardcoded but they could easily be resolved fromLAMBDA_TASK_ROOT
and_HANDLER
env vars.test.cljs
Build and deploy
I built the Docker image locally and pushed it to a private
ecr
container repository on my personal AWS account. Then I created a new lambda function from the console and told lambda to use the image from the repo.Benchmarks
NOTE benchmarks are naive and meant to just provide a "ballpark"
Benchmarks were made from the AWS Console by clicking the "test" button.
NodeJS 14 x86 AWS Default (baseline)
Cold start
2nd run
3rd run
Several subsequent runs
NodeJS 14 x86 Docker nbb as lib, code loaded on init
Cold start
2nd run
3rd run
Several subsequent runs
Conclusion
Next steps
nrepl
server locally?cljs
code with thenbb
executableBeta Was this translation helpful? Give feedback.
All reactions