Contact Us

AWS lambda - Introduction to writing serverless applications

What is serverless

Serverless is a cloud native development model that allows developers to build and run applications without having to manage servers.

In a serverless model, a cloud provider( such as AWS, Microsoft Azure, and Google Cloud) automatically allocates resources, takes care of servers, operating systems and scaling if needed. This way developers can focus on what really matters - i.e "INNOVATION".

What is AWS lambda?

AWS lambda is or lambda is a serverless service provided by Amazon web services. It allows developers to write code without having to worry about servers.

In lambda, you can write code in any preferred language, such as python, nodejs, ruby, go, and more. The code can then be uploaded to lambda and automatically executed based on event triggers from sources such as S3 bucket, and other configured triggers.

Write your first lambda function

I will walk you through the basics of lambda and how to create and write your first serverless function with lambda, and also how to test your function by manually invoking your function with sample event data.

Signing up for AWS

Before getting started, you need to create an AWS account using the following link

https://aws.amazon.com/resources/create-account

Locating lambda

Once you’ve signed into your console, search for ‘lambda’ in the search box. Select lambda from the search result.

AWS Lambda - Your Guide to Serverless Application Development

Create your first function

In the lambda page, click on create function.

AWS Lambda - Your Guide to Serverless Application Development

Once you click on the create function, it takes you to a page, the page contains a lot of information and options you don’t have to worry about for now.

AWS Lambda - Your Guide to Serverless Application Development

The only fields we will be filling out are the function name, and select a runtime language you wish to use. We will be using python3.9 for this demo.

AWS Lambda - Your Guide to Serverless Application Development

Click Create function at the bottom of the page.

On the page you are redirected to, you see more details, settings and features of the function you just created. The only section we will worry about is the code section.

AWS Lambda - Your Guide to Serverless Application Development

What’s happening in the code?

We already have a boilerplate hello world code, to give you an overview of what is happening. The lambda_handler function is the entry point i.e the function that gets executed once the lambda has been invoked. The body of the function is super straightforward, you can modify and throw in your own code as well.

AWS Lambda - Your Guide to Serverless Application Development

We have modified the code to some calculations, and we’ve replaced the hello world in the body of the json with the multiplication result, just to simulate what we will be getting back in a real world scenario.

Note: click the deploy button to any changes you make to the code

Creating Tests

Expand the dropdown in the Test button, and click configure test.

AWS Lambda - Your Guide to Serverless Application Development

A dialog box that looks like this will appear.

AWS Lambda - Your Guide to Serverless Application Development

Enter a name for your test event, make sure to select hello-world from the templates and click Save.

Select the test event you just created, then click Test.

AWS Lambda - Your Guide to Serverless Application Development

Congratulations, you have successfully created and tested your first serverless function.

Cleaning up

To delete the created function.

AWS Lambda - Your Guide to Serverless Application Development