Debugging AWS Lambda functions locally

There are very sophisticated industry standards like Serverless, but for small to middle size projects I find Serverless to be quite an overkill as you need to do lots of configuration. For my personal or hobby projects, I need a very simple solution where I can debug my application and also deploy code using npm scripts. By debugging I mean "debugging". Putting a breakpoint in the code and when I hover my mouse over the variable I want to see all available attributes, not logging things in CloudWatch. This has been one of the downsides of AWS Lambda. Not very easy to debug.

And for my personal projects I'm not really very keen to introduce big dependencies and make lots of configuration using yml files. Most of the time I create a NodeJS project locally, attach my AWS credentials and run the code. Finally when I'm satisfied with the final product I select all, copy and then paste it to the AWS Lambda console. Yes, very ugly but it works. I can debug it and mock all the parameters I need. Lately I've been thinking of making this process a bit faster. So I created this simple Boilerplate.

https://github.com/aliustaoglu/aws.lambda.debugger.git

I'm still using the same approach but with one small change. Instead of me manually copying and pasting the code into the AWS console, I make AWS.Lambda library to do it for me. Using createFunction and updateFunction, I create or update lambda function within the same NodeJS application I debug it.

I put my Lambda functions under apis/ directory. When I run Node project, index file calls "api1" using the configuration set in config.js.

- apis/
- ----/api1/
- ---------/index.js
- ---------/myLibrary.js
- ----/api2
- ----/api3
- index.js
- deploy.js
- config.js

deploy.js gets the api name (eg. api1), zips all files under this folder, and automatically uploads it to Lambda using aws-sdk commands.

When I need to deploy, I run this command:

node deploy api1

or even more elegant way:

npm run deploy api

If I want to deploy all the APIs:

npm run deploy :ALL

Deployed to AWS

You can get the boilerplate:

git clone https://github.com/aliustaoglu/aws.lambda.debugger.git