Jan 18, 2015 - Lambda-local - A local executor for Amazon Lambda


Developing Amazon Lambda function scripts on my local machine is a hassle. There are work-arounds, but it required me to write dirty, ad-hoc code. So I took some time to develop a node commandline tool called Lambda-local , that’ll execute your Lambda functions on your local machine, with whatever sample event data you want to feed it.


Just install with

npm install -g lambda-local

and use it with

lambda-local -l index.js -h handler -e event_samples/s3-put.js

You can feed any even data (JSON object) into the -e option.
I also added a -t (--timeout) option which let’s you set your own timeout limit in seconds.


The goal of this script is for devleopers to not have to write even 1 line of extra code in order to run their Lambda functions on their local machine. I thought it should all be handled by a simple command.
My further goal is to emulate whatever environment Amazon has set up on their Lambda console - Which includes:

  • Feeding sample event data
  • Setting a timeout limit
  • Setting a memory limit

I have two out of three (although the timeout part is still pretty rought). I want to try and implement a memory limit, maybe even just a warning.

Things I want to fix

Since the AWS console lets you load the aws-sdk module without installation, I wanted to emulate that.
The only solution I have now is to add Lambda-local’s node_modules path to the $NODE_PATH env variable, as well as your AWS credentials.
It would be great if I can have the lambda-local handle that automatically, but currently the users have to export manually.
I wish there is a better solution for this.

Personally I think Amazon Lambda has a great amount of potential, so I believe it’s important to have a dead-easy development environment for it, rather than having to upload your script/zip everytime. Hell, you don’t even have to sign up for Lambda to play with Lambda.

If AWS comes out with their own Lambda-local tool this will become obsolete, but until then, it’s a simple & independent tool that doesn’t require any learning curves and any additional code/configuration on your existing Lambda function scripts. I think it’s not too bad for a start.

So please try it out, fork it, or give me any feedback!

P.S. This was also my first time to write and publish a npm module. It was quite fun, and the publishing process is surprisingly easy. I really like it :)

Jan 17, 2015 - Amazon Lambda - S3 to RDS


I had an opportunity to try out Amazon Lambda at a Hackathon today. It was pretty fun, but unfortunately couldn’t finish it in time.

I like the concept of Lambda a lot - A relatively simple manipulation of streaming data shouldn’t require you to set up an EC2 instance and write your own script. There’s unnecessary overhead (actually setting up the instance; Installing required packages and stuff), and it’s just not scalable.

Lambda gives you a place to just “write and run code on the cloud”. It’s a big, bold leap from the world where business logic had to be implemented on EC2.

Input data from S3, send to RDS
What we’ve done is that we had data files being uploaded into an S3 bucket, and we wanted to process that data and store it into RDS(MySQL). Using Lambda, that was a relatively easy task to implement. I couldn’t get it right due to some permission problems of the Lambda execute and invoke, but once I tried again after I got home, I was able to easily make it work.

I’ve put the source here:

It’s basically using the usual MySQL module for node.js, and processing/inserting the data coming from S3. I’ll go over some important parts in writing this.

First is handling the content of the S3 data. Be be sure to cast the body of the data with String() for most usual file types.

	s3.getObject({Bucket:bucket, Key:key}, function(err,data) {
		if (err) {
			console.log('error getting object ' + key + ' from bucket ' + bucket + ' ::: '+err);
		else {
			var rawData = parseInt(String(data.Body).trim());

Once you get that, just insert like any other node.js script:

	Processor.connection.query("INSERT INTO `processed` SET val=?, created_at=?",
		[ data.val, data.created_at],
		function(err, info){
			console.log("insert: "+info.msg+" /err: "+err);

I think Lambda still has a lot of potential in what we can do. Writing whole applications with Lambda isn’t even a far-fetched idea.

The only problem using Lambda is the inefficiency of debugging code - I have to run it through the server to actually get sample data into event.handler(). I want to write a module that can invoke event.handler() on your local node.js, along with a sample event and context data. Maybe I’ll find some time to write it myself…

Jan 15, 2015 - Gather info & ask questions at Freenode IRC


I just discovered Freenode. It’s an IRC server for general technology, mainly open source stuff, but has things like hardware and electronics (Arduino) also. Seems like a great place to gather latest information on the technology. Also has a Minecraft channel and I like that a lot

I like it how everyone ask questions very freely, and other people try to answer them the best they can. I think this kind of atmosphere is very beneficial to developers and hackers. I smell a similar atmosphere as StackOverflow; Just a lot more casual.

To join:
The server host is irc.freenode.net. Just punch that into your IRC client and you should be connected.
/list and you can list all the channels. There are many, so find however many you like.

Some channels require you to have a registered identity. You can do that easily by typing in the command

/msg NickServ REGISTER {password} {email}

Then a verification e-mail should be sent to you. Follow the instructions and you’ll have a registered account.
Channels like ##php, #python and #iphonedev require registered accounts so I think it’s worth it.

I’m looking forward to reading and maybe participating on some channels throughout the following days.