Create a Lambda Function

A lambda function can be created using AWS console in a number of languages using NodeJS, Python and more. In this demo, the lambda function will be created using NodeJS. AWS already has a number of blueprints / samples in the console, however, an empty one (blank function) is used for this demo.

To create a lambda function, log in to AWS console and select Lambda from the Services tab. A page with the blueprints is displayed as shown below.
blueprint
The blueprints can be filtered using the programming languages or a name can be typed in. For this demo, click on the "Blank Function" blueprint.

On the next screen, the triggers can be set up. Triggers refer to certain actions within the AWS services like SNS, S3, DynamoDB (and more services) changes that can call the Lambda function. For example, a lambda function can be called when a file is uploaded to S3. The triggers can also be left blank.
triggers
In this demo, the triggers is left blank and the next button is clicked.

The next screen is the most interesting screen for developers where code can be written or uploaded. The minimum information that needs to be filled in are the name of the function, select a runtime (which should already be selected from previous screens), the default handler (this should already be selected) and an IAM role needs to be selected or created. There are other sections as well like the environment variables, tags and extra configuration but the default settings can be used.

The code is obviously the most important section but for demo purpose, the default code can be used for testing. The orher more important setting is the IAM Role setting that determines what the lambda function can call or access.
code

The next screen shows a summary of the function that is going to be created. Now, the function can either be created, edited or discarded. Once the function is created, it can be tested by clicking the Test button.
function

When the Test button is clicked, an option is provided to test the event. The default can be acceped and tested. When tested the output from the function is displayed, the logs are outputted and certain monitoring information like memory used is displayed.
summary

The important section from the code section to note is that the lambda function return option is defined using the callback which is called from the exports.handler function. The first parameter in the callback defines if any error has occurred and the second parameter defines the return value. The returned value can be a number, string, boolean or a JSON object.

Additional functions can be added to the code which can be called from exports.handler function as shown below.

In the modified code, an "add" function is added which is called from the exports.handler function. When tested, the correct output - 50 - is displayed.