Using Serverless To Save Up To Weeks Of Development Time

young business people working with digital tablet while discussing together in conference room
Reading Time: 3 minutes

In this article, we will talk about how we will be using serverless to save up to weeks of development time. To demonstrate this, we will be taking an example of a RESTful service which is pretty standard and many projects spend weeks of development time in early stages of the project to set it up.

If you take a look at the above diagram, it depicts a typical RESTful setup. You have a server serving your RESTful calls. The client sends a request to this server and it works as an API between the client and the database.

Setting up RESTful service for your project architecture becomes an integral part of the whole system and creating the server, setting up APIs, and testing takes weeks of development time.

Let us see how we can reduce this complexity now.

If you want a makeshift solution, you can use tools like Clam. It is a Python-based tool that helps you convert your CLI tool into a RESTful service. However, we are not going to talk about that now.

What Is Serverless?

Serverless is a cloud-native development model. It allows you to build, run, and test your applications without worrying about servers.

Serverless architecture is the new way to go. With serverless, you don’t have to worry about setting up and maintaining servers for your applications. Instead, you can focus on data.

Serverless Using AWS

AWS offers many services to facilitate serverless such as Lambda, Fargate, API Gateway, Eventbridge, SQS, etc. Most of these services follow the pay-as-you-go model.

Let us say you want to create server side SDK for your application that will serve the client SDK. This will obviously take some development time, and ofcourse a server will serve those REST calls.

But let us go back to the basics for a second. Why do we setup REST API service in the first place? To get data right? We can do that using serverless too!

For our example, we will be using the API Gateway and Lambda only.


You can create a Python based Lambda and use the boto3 library to access the components of the incoming API call such as the body in the following example, which is pretty standard if you have a POST call:

import logging
import json
import hmac
import hashlib
import re
import datetime
import boto3
import base64

from botocore.exceptions import ClientError
from urllib.parse import unquote

logger = logging.getLogger(__name__)

events = boto3.client("events")

def lambda_handler(event, context):
    return {"statusCode": 200}

API Gateway

We will use API Gateway to create our request methods that will give us the final endpoint that the client will hit.

A sample POST API with Lambda Proxy Integration turned on will look something like the following:

Lambda Proxy Integration helps you route your incoming API calls to your existing Lambda function. You can access the incoming body and the headers inside the Lambda function too!

You can have as many methods as you want, just don’t forget to deploy them to a stage.

Now it is time to test our API! Open postman and try to hit the endpoint you got from API Gateway with the body. You should get a 200 response.

Now, go to your Lambda function and check the Cloudwatch logs. You will see the logs will have the body you sent with the request!

Written by 

Mohit Saxena is a Software Consultant having experience of more than 2 years. He is always up for new challenges and loves to aggressively move towards completing the software requirements. On a personal front, he loves to climb mountains and is a big foodie.