Sitemap

AWS Lambda: Your Quick Start Guide to Going Serverless — The Sigma way

6 min readApr 17, 2018

A few minutes back I received a DZone mailer pointing me to an article titled “AWS Lambda: Your Quick Start Guide to Going Serverless”. This is a re-post from the original article here. Although the article is well written and gives a good introduction to AWS Lambda, I wanted to write an article on how the same process is extremely simplified by Sigma, the cloud based IDE for Serverless Computing.

Getting Started! Sign up for Sigma

I am assuming that you have already signed up for an account at https://sigma.slappforge.com and provided a GitHub account and and AWS account. If you want to try out the SLAppForge but would like to utilize a test AWS account instead — feel free to utilize a set of keys from Sigma!

Creating The Lambda Function

We simply create a new project from the initial welcome screen after login. Lets create a new project ‘ServerlessQuickStart’ — to be as close as possible to the original article.

Press enter or click to view image in full size
Creating a new Serverless Project with Sigma

The IDE opens up, with the skeleton of a new Lambda function (saved into a file named lambda.js) as follows.

Press enter or click to view image in full size
The Skeleton Lambda function presented in the IDE

The red color symbol at line #2 specifies that a trigger has not yet been set for this Lambda function. We will get to that in a little while. Lets follow up with the same code used in the original article. So we will replace the code to be the following.

Press enter or click to view image in full size
The first code snippet of the Lambda function

Next, we need to test this function. And similarly to the original article, we will use the built-in testing capability of the Sigma IDE by defining a test input sample as follows, by clicking on ‘Create an event’ drop down list from the menu. Next click on the ‘+’ button to define a test configuration — which you can also name, and configure as follows.

Press enter or click to view image in full size
Configure test input for the Lambda function

When you press the play button ‘>’ from within the test window (or later from the main IDE), the function is executed, and the result shown on the IDE in the Sigma Trail window.

Live SigmaTrail as you execute the function

To showcase this additional productivity improvement, lets additionally add a console log to our Lambda function as follows.

const result = event.number1 + event.number2;
console.log(‘First number :’ + event.number1 + ‘ Second number :’ + event.number2 + ‘ Result :’ + result);
callback(null, result);

Next, when this function is tested, the live output is shown directly within the IDE under the SigmaTrail as follows.

Press enter or click to view image in full size
SigmaTrail — Live logs from AWS Lambda functions

Connecting the API Gateway to the Lambda function

The Sigma IDE is a hybrid IDE, and it supports drag-and-drop integration with the AWS resources, in addition to full code level editing. To set an API Gateway endpoint to trigger our Lambda function, we simply drag the API Gateway into the Lambda function trigger line — where the red color marker was present.

Press enter or click to view image in full size
To set a trigger for the Lambda function, simply drag from the palette

We are presented with a window to name the API, and also assign a resource path to it. Lets assign the same API name and resource path as our original article.

Configuring an API Gateway trigger for a Lambda function

Optionally, under the ‘Show Advanced’ options, you can easily configure your API Gateway deployment to enable Lambda proxy integration, and / or CORS as follows. For our example, we will set both to true.

Configure Lambda proxy integration and Enabling CORS

Now, type in the same code as in our original article, and deploy the project by clicking on the ‘Deploy’ button on the tool bar. Note that the earlier red colored trigger on line #2 is now green, and that the left side palette, now shows that the configuration has “1” API gateway resource configured.

Press enter or click to view image in full size
Deploy the Lambda function with API Gateway integration

The first time you make a deployment — a popup will ask you to commit your code into your GitHub repository. Provide a commit message and commit your code! Of-course you can commit your code at anytime, even without a deployment.

Commit your code to GitHub directly

The first build will take a minute or two — but that’s because a lot of background work is being done for you behind the scenes on AWS. The details are shown in the changes summary presented to you, before the actual deployment kicks in. Proceed with the deployment by clicking on the Execute button.

Kick off the deployment!

After the deployment tasks complete, you will be presented with the status as follows, along with the URL of your API Gateway trigger.

Press enter or click to view image in full size
Successful deployment, showing the API Gateway endpoint URL

Now, as in the original article, you can use PostMan and request your API Gateway endpoint with a request and receive the response.

Press enter or click to view image in full size
Testing the API Gateway endpoint with Postman

Quick Deploy to tweak the code in seconds

Now lets look at some of the additional advantages of using the Sigma IDE. Since we do not have logging, we introduce a console log line to our code as follows.

console.log(‘First number :’ + firstNumber + ‘ Second number :’ + secondNumber + ‘ Result :’ + result);

Simply click the ‘Quick Deploy’ button from the toolbar, and your code will be refreshed in just a few seconds — much faster than with the raw AWS facilities.

Press enter or click to view image in full size
Quick Deploy the code with logging enabled

Built in HTTP, SNS and SQS Clients and more

Lets also checkout the built-in HTTP client of the Sigma IDE. Note that unlike Postman, the built-in toolbox of the IDE also has a SNS and SQS client already, with more test capabilities being added as we speak! However, note that at present, we have to add the “Access-Control-Allow-Origin” header to our response as follows to avoid CORS issues as per this article, since our client is hosted on the sigma.slappforge.com domain.

Press enter or click to view image in full size

Dependency Management and Environment Variables

Although we have kept the basic scope of this article the same as the original article, be sure to look into the other capabilities of the Sigma IDE such as Dependency management and Environment variables manipulation. At present the Sigma IDE also supports the following AWS resources, with more to follow soon!

API Gateway, Cloud Watch, DynamoDB, Kinesis, S3, SNS, SQS, RDS and SES!

--

--

Asankha Perera
Asankha Perera

Written by Asankha Perera

Founder and CEO Aayu Technologies LLC & AdroitLogic. Disrupting B2B AS2/EDI with modern Serverless technology