Improve your AWS lambda development with SIGMA

Randika Navagamuwa
Think Serverless
Published in
4 min readFeb 28, 2018

--

A few weeks back, I wrote an article about implementing a Simple Authentication Service with AWS Lambda. Implementing that service was not that straightforward. If you are doing that on your own, then you need to go through several docs on API Gateway, RDS, and Lambda. Believe me that is not an easy thing to do.

With Sigma, you only need an AWS Account, Github Account and a Web browser. Yes, you are right, you don’t have to refer the AWS docs. All the hard work including deployment is handled by Sigma. You don’t even have to login to your AWS console.

Sigma itself is a native Serverless system. Its not an existing cloud IDE re-branded as a Serverless application development environment. Hence, it does not require a server/VM or an EC2 instance as a backend. It’s a customized editor only for the development and deployment of Serverless applications, and hence lightweight and fast, and it operates completely within your browser. (https://www.slappforge.com/)

Let’s try to implement the same authentication service with Sigma IDE.

Create an account on Sigma and provide your AWS Credentials. (You can refer the article “Serverless: Getting started with SLAppForge Sigma” to get a clear idea of setting up the IDE including the getting AWS credentials)

Initially IDE will look like this. You can see all the supported services on the left hand-side panel.

If you are too lazy to read, just select this sample from Sigma IDE and deploy it on AWS. :P

First you need to set API Gateway as the trigger for this lambda. At the moment no trigger has been set for this lambda function. Red color icon is to notify that. To do that, drag and drop API Gateway resource on to the function. Fill up the fields with the relevant information.

After setting up the trigger you can see that the red color icon turns to green. This means that the trigger has been configured properly.

Then drag and drop RDS resource from the left panel and fill up the fields.

Use the following query as the initial query.

CREATE TABLE users (    
UserId int NOT NULL AUTO_INCREMENT,
Email varchar(255) NOT NULL UNIQUE,
Password varchar(255) NOT NULL,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
PRIMARY KEY (UserId)
);

Select Query as the preferred operation and put the following SQL query and the inserts for the values.

Query : INSERT INTO users (Email, Password, LastName, FirstName, Address) VALUES (?, ?, ?, ?, ?)

Inserts : event.email, event.password, event.lastName, event.firstName, event.address

You can customize the generated lambda as you wish and the final lambda should be like this

Signup lambda function

Now the signup API is done. Note that we haven’t configured the sign in API. Similarly, you can configure that by adding a new lambda to your project. Everything is same as the above except that, the same database should be used for this lambda as well. So instead of creating a new RDS instance, select the previously created instance from the existing tab.

Query : SELECT * FROM users WHERE Email = ? AND Password = ?

Inserts : event.email, event.password

Return true or false accordingly after checking the user. The complete lambda should be as follows

Sign in lambda function

Now all the work is done. Just click on the deploy button to build and deploy the project on AWS. After successfully deploying the project IDE will notify you. Now the testing part comes in.

Testing

  • Now, first to signup, send an HTTP POST request to the signup endpoint which you can find from the API Gateway console,t with a sample JSON payload as follows.
{
"email": "randika@adroitlogic.com",
"password": "12345678",
"lastName": "Navagamuwa",
"firstName": "Randika",
"address": "12 A /5, Pirivena Rd, Mount Lavinia"
}
  • In the signup call an entry will be added to the users table. If you were successful you’ll get a 200 OK response with the response message Successfully added a new user with email.
  • Then, to check the signin, send an HTTP POST request to the signin endpoint (https://{api-id}.execute-api.{region}.amazonaws.com/prod/signin) you found in the earlier steps with a sample JSON payload as follows. Note that the values should match the values used in signup request.
{
"email": "randika@adroitlogic.com",
"password": "12345678"
}
  • If the signin is successful you’ll get a 200 OK response with the response message true.

Please note that this is a simple service, which is deployed just to demonstrate the usages of some AWS Services.

Get in touch with SLAppForge Community : https://launchpass.com/slappforge

--

--

Randika Navagamuwa
Think Serverless

Solutions Architect. Open Source Enthusiast. Works at StarTree Inc. Graduated from University of Moratuwa, Sri Lanka. | https://rnavagamuwa.com