Einführung in Serverless ComputinIntroduction into serverless computing with AWS Lambda

Having a scalable infrastructure to execute code on servers in the cloud while minimizing cost is nothing new. Since public cloud providers enable organizations to implement are the state-of-the-art IT architectures on instances hosted in the cloud. Function as a service (FaaS) is the natural evolution of this concept. But it goes beyond spinning up an instance and running your application on it. FaaS provides a user with even more freedom since users are enabled to focus on an application‘s code without having to worry about managing infrastructure at all. This is true for all serverless applications, at least at AWS.

AWS Lambda sits at the core oft he serverless platform at Amazon Web Services. It is an integral part of service-oriented architectures and therefore triggered by events. It scales with demand and provides built-in monitoring and logging. And naturally, it is integrated with a lot of services in AWS. It supports many programming languages: Java, Go, PowerShell, Node.js, C#, Python, and Ruby. The same concept can be found on any major public cloud provider. Google Functions and Azure Functions belong to the same class of services and probably even use similar technology internally.

Why you should consider AWS Lambda and when to use it?

The ability to focus purely on your business challenges and the code you need to solve is a big advantage from a development point of view. But there is another advantage in using AWS Lambda and that is cost optimization. Usually, you spin up an EC2 instance to run your application which is billed per compute capacity by the hour/second. This can get expensive very quickly. Sure, there are different types of instances and you can reduce your operational costs by incorporating reserved instances (RIs) once you know your base demand. And for non-critical applications, you can bid on spot instances which are very cheap in comparison.

But in many cases you want to execute code just once in a while, just don’t have enough demand to buy a RI or the application is not suitable for spot instances. In such cases, AWS Lambda poses an alternative. It bills only after a certain number of requests and the used time for processing. Due to free tier on AWS, it can happen that some applications a virtually free of cost (disregarding the cost of developing and maintaining the code). Free tier for AWS Lambda includes 1.000.000 free requests per month and 400,000 GB-seconds of compute time per month. In case you worry that lambda can respond in time: Lambda functions are usually ready for usage within milliseconds!

How it works

A lambda function consists of three parts. Function Policies control which services can invoke the lambda function. This can be data stores, endpoints, repositories, or message services. Table 1 shows examples for every possible category.

Event Source CategoryExample
EndpointsAlexa, API Gateway, AWS Step Function, Amazon IoT
RepositoriesCloudWatch, CloudFormation, CloudTrail, CodeCommit
Data StoresS3, Dynamo DB, Kinesis, Cognito, Aurora
Message ServicesSQS, SNS, SES, Cron Events

Table 1: Event Sources

The IAM Execution Policy specifies, what the function is allowed to do. And finally, the code which implements the business logic.

Possible applications for serverless functions

Serverless Web Applications

This is an interesting use of lambda functions since it involves a few other serverless services from AWS. Figure 1 shows a high-level architecture. Amazon S3 is used to host the static frontend of a website. The dynamic functionality is provided by the API Gateway which provides public endpoints fort he frontend. The API Gateway, by default, protects against DDoS attacks and caching abilities. Finally, the AWS Lamda is used to implement the business logic and used as an internal endpoint for the API Gateway. All these services scale on demand and are highly available so you don’t have to worry about downtime ever again.

Figure 1 – Example architecture of a serverless web application.

Real-Time Data Transformation

You can use AWS Lambda and Amazon Kinesis to process real-time streaming data a lot of applications. Figure 2 depicts an IoT use case where one (but can be multiple) internet-enabled device stream their data into the AWS Cloud. Amazon Kinesis streams this data directly to Lambda where some processing steps are added. This can be calculating metadata, cleaning the data, or run some checks on the data before writing it to a database.

Figure 2 – Example architecture for real-time data transformation

Other applications may include real-time log analysis, processing of uploads to S3, or using AWS Lambda as an IoT backend.

Here at PROTOS Technologie we are specialized cloud engineers which can support you with leveraging serverless technology and service-oriented architectures.