
Run Any JavaScript Function in the Cloud - SwellJoe
https://github.com/mentum/lambdaws
======
spoiler
I find it bizarre how the code examples provided on github use λ. I know
JavaScript allows this, but I can't imagine myself switching to a greek layout
to type λ. Otherwise, I have to copy and paste it, which adds a lot of
overhead.

I also remember someone suggested a ±/∓ signs for CoffeeScript at one point,
and they justified it as "Well, _I_ can type it using <insert fancy keyboard
combination> on _my Mac_."

I know this is slightly off-topic, but I had to point it out because I feel
like it stabbed me in the eye.

Anyway, I do like the idea of _Lambdaws_ , kudos to the author.

~~~
TeMPOraL
I'm pretty sure it is meant only for aesthetics and readability of the demo.

Speaking of readability, I actually use a package for my editor that _renders_
word "lambda" as λ. This way, I get to see code that's more pleasant to read
and don't have to type in (and save) any greek characters.

~~~
cturhan
Which editor?

~~~
TeMPOraL
Emacs.

There are various code snippets for that floating around, e.g.
[http://www.emacswiki.org/emacs/pretty-
lambdada.el](http://www.emacswiki.org/emacs/pretty-lambdada.el).

------
je42
MMh. Using toString to serialize a JS function breaks for some functions
doesn't it:

[https://github.com/mentum/lambdaws/blob/master/lib/LambdaHel...](https://github.com/mentum/lambdaws/blob/master/lib/LambdaHelper.js#L79)

It seems here is a discussion about the topic:
[http://perfectionkills.com/state-of-function-
decompilation-i...](http://perfectionkills.com/state-of-function-
decompilation-in-javascript/)

~~~
_Marak_
To my understanding, this library is intended to run in a some-what fixed
environment ( server-side node.js ).

I'm unsure if you will run into any of the serialization issues mentioned by
Kangax, as developers will be using the same ( if not very similar ) versions
of v8.

~~~
eridal
I feel like there's no sane way for the developer to understand that he's
runnning in a different evironment

suppose:

    
    
       var i = 0;
       var localCaller = remoteBundler(function() {
           // this will be run at server-side
           i += 1; // oops .. "i" does not exists on server
       });
    
       localCaller();
    

and yes, this is could be easily spotted, but I've seen so many guys really
stuck with so naive errors (eg mongodb's reduce function)

~~~
icebraining
Can't the library detect the closure? I'm pretty sure I could do this in
Python.

------
amvp
This is cool. I'm pretty excited about AWS lambda. Keep in mind the current
limitations of the AWS lambda at present: A process can't take longer than
60s. Only 25 concurrent executions. The zipped package containing your code
and all dependant libraries can't be larger than 20MB.

------
alexatkeplar
Interesting! For people who prefer a less abstracted approach, check out:
[https://www.npmjs.com/package/grunt-aws-
lambda](https://www.npmjs.com/package/grunt-aws-lambda) (with accompanying
blog post: [http://hipsterdevblog.com/blog/2014/12/07/writing-
functions-...](http://hipsterdevblog.com/blog/2014/12/07/writing-functions-
for-aws-lambda-using-npm-and-grunt/)).

~~~
scottmotte
Nice. And for yet another less abstracted approach, check out:
[http://github.com/rebelmail/node-lambda](http://github.com/rebelmail/node-
lambda) (also with accompanying blog post:
[http://www.mot.la/2014-12-07-amazon-lambda-best-practices-
de...](http://www.mot.la/2014-12-07-amazon-lambda-best-practices-development-
and-deployment.html))

------
cturhan
The first time I saw Greek letters in a code was d3.js source code.

[https://github.com/mbostock/d3/blob/master/src/geo/area.js#L...](https://github.com/mbostock/d3/blob/master/src/geo/area.js#L34-L63)

It's a pure pain for me to type these letters. How do you write them besides
copying/pasting?

~~~
quarterto
My custom keyboard layout[1] has a third and fourth level (Alt+[Key],
Alt+Shift+[Key]) containing various useful Greek and mathematical symbols,
e.g. λσγδ∀∃∈⊂∞∅ℤℕ←→↓↑

[1]: I used Ukelele on Mac but there's also Keyboard Layout Creator for
Windows and manually editing xkb files on Linux

------
claudiowilson
Aside from being pretty cool, what's the use case for this?

~~~
ajkjk
It's cool precisely because it's useful! Have an expensive computation task?
Just dump it onto the cloud instead of running it locally. This is probably
the most streamlined way to do this that I've ever seen.

~~~
capisce
If you have an expensive computation task and you're paying for computing
time, do you really want to be using JavaScript for the purpose?

~~~
ajkjk
Probably not, but this isn't purporting to be the best way to do it. It's just
a cool thing you can do in your JS code.

Especially nice for spinning something up with zero overhead. Maybe not
optimal for production apps. Maybe good if you're constrained on server
resources but less so on budget. Maybe good if you're still on the Lambda free
tier pricing.

------
_Marak_
This is a pretty neat trick / feature to add on top of a microservice hosting
platform like Amazon Lamba. Automatic serialization, uploading, and queuing of
your microservice from a running application. Normally this is done manually
with a source code upload or git push.

If anyone is interested in an alternate open-source microservice platform to
AWS Lamba, try checking out [http://hook.io](http://hook.io)
[http://github.com/bigcompany/hook.io](http://github.com/bigcompany/hook.io)

No hook.io users have requested this novel functionality that Lambdaws
performs ( yet ), but I suspect we'll add it to hook.io in the future.

------
pokpokpok
You can't use this client side, correct? due to the fact you'd be publishing
your aws key?

~~~
detaro
Also because people could do arbitrary computations under your account
(Bitcoin/Litecoin mining in JS anyone?)

------
adamrneary
This is useful, but I am not sure at scale (i.e. a constellation of micro-
services working together) I would want some of this functionality abstracted
behind a library. I prefer gulp and wrote a couple articles talking through a
simple process for local development, testing, and deployment if anyone finds
it useful:

* [https://medium.com/@AdamRNeary/developing-and-testing-amazon...](https://medium.com/@AdamRNeary/developing-and-testing-amazon-lambda-functions-e590fac85df4) * [https://medium.com/@AdamRNeary/a-gulp-workflow-for-amazon-la...](https://medium.com/@AdamRNeary/a-gulp-workflow-for-amazon-lambda-61c2afd723b6)

------
atonse
This is really cool but how do you trigger the execution with SQS? AFAIK, AWS
lambda functions can only be triggered by DynamoDB or Kinesis streams, or S3
events. I didn't know you could trigger them off SQS as well.

~~~
alexatkeplar
It looks like SQS is only used for the out-of-band return path. The execution
is triggered with the AWS SDK's invoke async option:

[https://github.com/mentum/lambdaws/blob/master/lib/LambdaHel...](https://github.com/mentum/lambdaws/blob/master/lib/LambdaHelper.js#L154)

Documentation on this option:

[http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-
cust...](http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-custom-
events-invoke.html)

~~~
atonse
I didn't know about invoke async. Thanks!

------
shanemhansen
It seems weird to me to have language specific sandboxing services. We should
be able to execute any code safely "in the cloud" (which I'm going to
charitably interpret as being automatically distributed over N machines).

You can use things like app armor profiles for runtime sanboxing or google's
nacl for statically verified binaries. Heck, even java bytecode would be more
flexible than javascript.

------
tericho
This is interesting. The main use cases seem to be large computations, since
HTTP calls would be more expensive any almost any routine operation.

~~~
dagw
Well, not that large since it will kill your function if it takes more than 60
seconds to run.

------
IkmoIkmo
Genuine question, didn't we have NodeJS for that? I haven't looked into this
properly, but I what is the angle here exactly? Thanks in advance.

~~~
rattray
Read the README; this runs a function on _other_ instances in the cloud, on-
demand. I agree the title is confusing. For example, you could write a
parallelizable, computationally intense function, and have it run in parallel
in AWS, directed from a script on your laptop. Without having to set up
servers, upload code, etc.

------
LAMike
So could a service like jsfiddle allow for npm modules to be loaded in? It
could be a cool premium feature

~~~
m90
There's requirebin already which does that.

------
zubairov
The simplest PaaS ever, nice approach - should have been done by AWS

~~~
aaronbrethorst
Except it was done for free by some upstanding person. If it proves to be
successful, expect to see AWS roll it out in 2017 or 2018.

------
irunbackwards
Is it just me or is this really beast

