How to Create, Test and Deploy Lambda functions to AWS


Lambda is one of the service offering from Amazon AWS for the Serverless Computing. Google also provides similar services called “cloud functions”. In simple words, write your code  and run them on the Lambda platform. Currently Lambda supports the programming languages Java,Python,Node 0.10 and Node 4.X. To make the development & deployment workflow easier i have used a node based Command line tool  Node-Lambda to locally run and deploy node.js application to Amazon Lambda. Lambda functions either added as Inline script or can be deployed as a Compressed Zip file.

This utility provides the following commands from development to deployment

node-lambda setup : Setup a new Lambda template script
node-lambda run   : Run the Lambda Code locally
node-lambda package : Package the lambda function as a zip file
node-lambda deploy  : Deploy them to the Amazon Console.

Sample Lambda Script.exports.handler = (event, context, callback) => {console.log(event);};

FAQ’s on Lambda & NodeJS :

1.Does filename matters when zipping the lambda package?

The zip filename can be anything. It all depends on the handler file. This can be configured in the Lambda Settings index.handler. In this case the main file should be index.js

2.What about the node_modules dependency ?

Node modules like aws-sdk are available by default in the aws execution context. If you are using other than aws-sdk then you should package those node_modules along with the zip package.

3.Is package.json required in the zip package?

No. package.json is not needed. Also, you can’t run a npm install there. But it can be used as a reference for others to know the dependencies.

4.Can i able to download the latest lambda function which i uploaded earlier?

Yes, From Amazon Lambda console you can download the last uploaded version of lambda

5.How to debug the Lambda function?

You cannot debug like a step-in & step-out model. But you can use the console.log and log your events to the CloudWatch

6.How to invoke the Lambda functions?
Lambda can be invoked in the following ways

– Invoke via Lambda API
– Map the Lambda to a API Gateway and Access the API
– Trigger the Lambda function automatically based on defined events like (S3 Creation,S3 Deletion etc)

7.How to manage Lambda function deployments ?
Lambda can be deployed from the AWS Console or using AWS API “updateFunctionCode”. Ensure you have the necessary access to use the updateFunctionCode API method.


Technical Geek - Gadget Enthusiast - Loves Programming C#,PHP & IOS - Blogger About

More Posts - Website

Follow Me:
TwitterGoogle Plus