Articles | February 23, 2023

Using AWS Lambda functions – development of serverless applications

Read the article and find out more about using serverless technologies based on the example of the AWS Lambda function. Learn about the advantages and disadvantages of a serverless approach and the costs involved.

serverless applications

At a time when the popularity of microservices architecture is growing, in addition to designing and writing applications, you should also take care to manage these applications, and choose solutions for orchestration, network layer management, etc. This usually involves building a dedicated and specialized team.

If you want to avoid this and make life a bit easier, you can write scaling serverless apps using serverless architecture delivered by a cloud service provider, e.g., AWS. Read on to find out more about using serverless technologies based on the example of the AWS Lambda function. Taking advantage of a serverless environment, you may wonder what costs are involved, as well as think about the advantages and disadvantages of a serverless approach.

Introduction to a serverless architecture. What is AWS Lambda?

AWS Lambda is an event-driven serverless Function as a service (FaaS). The Lambda function allows you to write and deploy code, and manage the application and eliminates the need to maintain your own servers. It allows you to create applications in the cloud, e.g. using the popular ZIP deployment method.

nearshore 2023.02.23 graphic 1

AWS serverless Lambda functions

Function as a Service is gaining popularity because the user only pays for the processing time of a given function. For example, in the case of the REST service that triggers Lambda, the fee is charged only for a single endpoint call (this approach is known as pay-as-you-go) while maintaining availability, reliability and scalability.

Business logic. How does AWS Lambda work?  

nearshore 2023.02.23 graphic 2

Trigger

This is an event that triggers AWS Lambda. The trigger can be 1 or more events from different AWS services, e.g.:

  • Call via API Gateway (REST call)
  • The addition, modification or deletion of a new file on Amazon S3
  • Message from the SQS queue or from external systems such as Atlassian, Symantec, PagerDuty and many others.

Each of these events could be a topic for a separate article, so if you would like to explore this matter further, I encourage you to read the Lambda Amazon Web Services documentation where everything is described in detail.
It is worth mentioning the type of the function call (InvocationType). Lambda can be triggered in two modes:


Synchronous – This mode can be compared to a REST call in which a request is sent and a response is received, which is why it is called a request/response type.

Asynchronous – In this mode, the request to Lambda is sent to the event queue. If an error occurs, the request will be sent twice at most. AWS does not guarantee that all messages will be delivered – for example, when an application cannot handle a given number of queued events. Since we do not know whether the function has been executed, using DLQ (dead-letter-queue) might be useful. In this case, the Destination Block helps us. This mode of triggering is called event triggering.

Serverless application model – supported programming languages

The function code can be written using one of the languages supported by AWS. Currently, we can choose from programming languages such as:

  • .NET (C#)
  • Java
  • GO
  • Node.js
  • Python
  • Ruby

Using technology such as e.g. Node.js, you can take advantage of the built-in editor to write a function. You can also provide the code for an externally created function as a package in a ZIP file. There are various plugins for development tools that can help you create a structured code package (such as Apache Maven Shade creating Uber-JAR).

Destination

This block is responsible for sending notifications about the status of the function execution. In the case of correct or incorrect execution, AWS can send a notification to one of the 3 available channels:

  • Topic SNS
  • Message on SQS
  • EventBridge

or run another Lambda function.

However, this functionality will only work while triggering the Lambda function asynchronously. When testing Lambda in UI AWS, the Destination Block will not work because the request is sent in the request/response mode, not event mode.

AWS Lambda Infrastructure

AWS Lambda is an FaaS which means that Amazon Web Services manages the infrastructure. The function code itself is stored on AWS S3. We should remember the limits, such as those concerning the amount of code in GB that can be stored in a given cloud region, among others. For the European region, the limit is 75 GB.

Using a serverless platform. What is the life cycle of your application?

nearshore 2023.02.23 graphic 3

When the request is sent to the Lambda function, it is launched as an instance of our service in the internal environment. It is similar to the AWS EC2 environment (virtual machines on AWS). However, the user does not have access to this environment. When we try to launch an instance, the AWS mechanisms check whether such an instance has already been launched, and – if it is running – whether it is processing the request.

If the instance is busy, AWS Lambda mechanisms create a new instance of the function. Otherwise, it uses the current instance or, if the instance does not exist, creates a new one. If a function instance remains unused for a long time (AWS manages the time itself), the function instance is removed.

AWS Lambda and scalability

Now let’s move on to an aspect which is inseparable from the cloud, namely scalability. AWS Lambda, like any other service, has certain limitations, one of which is the limit of active instances for a given region – in the case of European AWS regions it is 1000 active instances. This pertains to all of the Lambda functions we have in our account in a given region.

To ensure that the minimum number of instances is always launched when needed, you can book the number of instances per function in the Lambda configuration. Also, it is worth mentioning that each Lambda instance has access to the internal memory (/tmp) with a capacity of 512 MB which is not deleted until the instance is removed.

AWS Lambda parameters and configuration

When creating Lambda, two important parameters must be provided:


Memory – this is the available RAM assigned to the instance of our service. In the event of exceeding the memory limit, the instance is stopped. Currently, the maximum memory limit is 10 GB.
Timeout – the maximum time for the function execution. This is a very important cost-limiting parameter. If we set this parameter, for example to 30 seconds, and our function execution time is longer than the response time, this function will be stopped. You can set the maximum time of 15 minutes.

AWS Lambda – important configuration elements:

  • Environmental variables – this is where you can set the variables that will be transferred to your function (e.g. a bucket location on AWS S3). 
  • Permissions – Lambda access settings, e.g. to S3, RDS AWS etc. 
  • Network Settings – From Security Groups to Subnets to VPC. This is important if, for example, the database is in a specific Virtual Private Cloud. 

What else is worth remembering when creating AWS Lambda?

  • The selection of the technology in which the functions are written – this has an impact on the performance of the application. Using AWS Lambda, we pay for the duration of the service and memory used. The “thicker” the application is, the more memory it uses, and the longer the cold-start takes. This means that when triggering the function for the first time, we will simply pay more. In addition, the application will have a larger codebase, which will use more space on the Amazon S3. Among the technologies I have had the opportunity to use, the performance of Node.js was the best.
  • Error logging – the response from Lambda itself will not provide us with useful information, and Lambda monitoring and debugging is very limited. Keep in mind that logging on to AWS also includes costs if you need more advanced use than the free tier (trial version) allows. For this reason, I encourage you to familiarize yourself with Amazon CloudWatch pricing.
  • Creating Lambda with AWS CloudFormation – using AWS services will allow you to save time on creating and configuring resources and looking for dependencies. Moreover, it allows you to avoid many problems related to e.g. access or VPC (such as VPC configuration, so that AWS Lambda is visible to a database, or other services that we do not make available to the public).

The cost of Lambda AWS. Is it good value for money?

The answer is: it depends. In AWS Lambda, you pay for the amount of time you use the function for and the memory used. The billing unit used by AWS is gigabytes per second (GB / sec). You also pay for the number of requests; however, in the starter package for a new account (free tier) you get 1 million requests per month and 400,000 GB / sec. That’s quite a lot for free testing of AWS cloud solutions.

Example of costs

  • 1 million requests cost $0.20
  • 1 GB / sec. costs 0.0000166667 $ (in the case x86 architecture)

Let’s assume that we have an application serving 500,000 requests a day which needs 512 MB of memory. The total monthly cost is approximately $267. This is the only cost we will bear as we don’t need to maintain the application infrastructure (k8s, Service Mesh etc.).
I wouldn’t like to compare the costs to the server instance here, e.g. EC2, because this comparison would not be adequate. I will leave everyone to judge which approach is more viable for them.

Read also: Cloud services and trends for 2022

AWS Lambda – advantages and disadvantages

Lambda functions – advantages

  • Using a scripting language, you can quickly write an optimized function
  • Saving time on infrastructure management
  • Automatic scalability

Lambda functions – disadvantages

  • Depending on the selected technology (e.g. Java with Spring Boot), there may be a long boot time on the first call (cold-start) 
  • Monitoring limitations and low application debugging capabilities 
  • Due to the relatively short maximum time of function execution and the RAM limit, it will not work well for applications with a high computational overhead.  
NS case study IT Consulting cover

OUR SPECIALIZATIONS

Software Outsourcing Services That Meet Cutting-Edge Requirements

Find out more!

AWS Lambda and serverless architecture – summary

Cloud technologies enable developers to build serverless applications without having to manage servers. You can choose from wide variety of capabilities and services, like AWS Lambda. It is worth considering whether AWS Lambda will “lighten” your infrastructure and allow for cost optimization. As part of the analysis, it may turn out to be a tailor-made solution. Of course, AWS Lambda is not an ideal tool. It has its limitations, and it will not always allow you to achieve your goal.

I hope that I have been able to introduce AWS Lambda, along with its advantages and disadvantages. I encourage all who are interested to explore this subject further and learn about the solutions allowing us to use the potential of AWS Lambda – S3 or SQS libraries. It is also worth investigating solutions allowing you to reduce the “cold-start”. There are many of them – AWS Serverless Java Container Spring to name one – but that is a topic for a separate article.

Despite his experience, he still has the feeling that there is a great deal of programming knowledge still to explore. Bartosz learns something new every day and admits that something constantly surprises him. He is fond of algorithmics, cloud solutions, and difficult programming problems. In his private life, he’s a fan of strength athletics and puzzles.

Exclusive Content Awaits!

Dive deep into our special resources and insights. Subscribe to our newsletter now and stay ahead of the curve.

Information on the processing of personal data

Exclusive Content Awaits!

Dive deep into our special resources and insights. Subscribe to our newsletter now and stay ahead of the curve.

Information on the processing of personal data

Subscribe to our newsletter to unlock this file

Dive deep into our special resources and insights. Subscribe now and stay ahead of the curve – Exclusive Content Awaits

Information on the processing of personal data

Almost There!

We’ve sent a verification email to your address. Please click on the confirmation link inside to enjoy our latest updates.

If there is no message in your inbox within 5 minutes then also check your *spam* folder.

Already Part of the Crew!

Looks like you’re already subscribed to our newsletter. Stay tuned for the latest updates!

Oops, Something Went Wrong!

We encountered an unexpected error while processing your request. Please try again later or contact our support team for assistance.

    Get notified about new articles

    Be a part of something more than just newsletter

    I hereby agree that Inetum Polska Sp. z o.o. shall process my personal data (hereinafter ‘personal data’), such as: my full name, e-mail address, telephone number and Skype ID/name for commercial purposes.

    I hereby agree that Inetum Polska Sp. z o.o. shall process my personal data (hereinafter ‘personal data’), such as: my full name, e-mail address and telephone number for marketing purposes.

    Read more

    Just one click away!

    We've sent you an email containing a confirmation link. Please open your inbox and finalize your subscription there to receive your e-book copy.

    Note: If you don't see that email in your inbox shortly, check your spam folder.