Serverless architecture became an innovative trend in the IT industry. The term serverless doesn’t imply that no servers are involved. As an extension to cloud computing, it allows developers to build and deploy applications without being involved in server-side operations. A third-party service handles all of the backend operations and infrastructure management tasks. It gives developers more time to focus on the application code and business logic. In general, serverless architecture has numerous benefits over traditional servers. In a serverless platform, developers don’t have to install, maintain or administer the server-side software. Serverless platforms handle the large volume of requests by automatically scaling the applications where traditional server architecture failed. Serverless facilitates companies to pay only for the usage of resources instead of fixed server costs, and there’s no billing when the code isn’t running. It also has built-in high availability that ensures the continuous uptime of the system for an extended period.
AWS allows to build and run serverless applications by providing many services that can be considered components of the AWS serverless architecture. These components include:
Compute: AWS Lambda
APIs: Amazon API Gateway
Storage: Amazon Simple Storage Service (Amazon S3)
Databases: Amazon DynamoDB
Interprocess messaging: Amazon Simple Notification Service (Amazon SNS) and Amazon Simple Queue Service (Amazon SQS)
Orchestration: AWS Step Functions and Amazon CloudWatch Events
Analytics: Amazon Kinesis
In 2014 Amazon introduced AWS Lambda, an event-driven serverless computing platform, as a part of Amazon Web Services (AWS). It’s a service that belongs to the compute domain of services that AWS provides. AWS Lambda excludes the developers from server-side operations such as provisioning, scaling, maintenance, etc. Since its initial release, AWS Lambda has had a significant influence on the rise of serverless computing and became one of the most used AWS services. In an event-driven architecture, event functions respond to the triggers and run custom code. As an event-driven platform, Lambda responds to the events such as object uploads to Amazon S3, Amazon SNS notifications, or API actions generated by AWS services. Therefore, AWS Lambda can be considered a Function-as-a-Service (FaaS), though its capabilities extend beyond that. AWS Lambda consists of three main components: function code, event sources, and function configuration. Lambda function consists of the code which runs as a response to the events generated by AWS services. When there are multiple events, Lambda will create multiple copies of the function to respond to them.
Simply put, the code that runs on AWS Lambda is known as the Lambda function. The function code should be written in a stateless style. It means that function results are not affected by previous events and it enables the scaling capabilities of the Lambda function. Developers can write function code in any programming language supported by AWS Lambda, including Node.js, Python, Ruby, Java, Go, C#, and PowerShell. It also provides a Runtime API to run code written in other programming languages.
In AWS Management Console you can choose one of four options to create your function:
Author from scratch: Create the Lambda function from scratch.
Use a blueprint: Use sample code and modify it to build the application.
Container image: Create the Lambda function from the container image
Browse serverless app repository: Deploy sample applications from the AWS Serverless Application Repository.
When you create a function, you can specify the properties such as the function name, the programming language that you use to write functions, permissions/execution role, etc.
AWS Lambda helps organizations to reduce the cost and complexity of their IT operations by managing the infrastructures. Lambda uses a pay-per-use model for pricing, which depends on the factors such as the number of requests, execution time, and memory usage, etc.
AWS Lambda allows developers to build and run cloud-based, serverless applications by integrating with more than 200 AWS services. Developers could upload the function code to AWS Lambda or directly write the code in the Lambda console and then set conditions to execute the function when a trigger event occurs. Once the developer completes the code, AWS Lambda will create a zip file that includes the code and its dependencies and uploads it to the Amazon S3. Using tools such as Docker CLI, developers could package the Lambda extensions, function codes, and their dependencies to create lightweight standalone executable software called containers. Then, it uploads to the container registry hosted on the Amazon Elastic Container Registry (Amazon ECR). The containers are usually isolated from its surrounding and it helps to reduce the conflicts between the teams that run different software on the same infrastructure.
When an application or other AWS service sends data or requests to AWS Lambda, it will launch a container image to handle the request. A single container can handle one or a few requests. But when the number of requests increases, Lambda will create multiple containers and share requests. When the request count decreases, Lambda will proportionally reduce the number of containers. All of the container-related tasks are entirely handled by AWS Lambda.
For instance, AWS Lambda can be used to resize the images uploaded to the Amazon S3 bucket. A user can take a photograph and upload it to the Amazon S3 bucket in a raw format. If the image size is different from the standard size, it needs to resize. When a new object is added to the S3 bucket, AWS Lambda will be triggered and run the function to resize the image that fits the devices, including PC, tablets, or smartphones.
The pay-per-use approach in AWS Lambda provides a cost-effective pricing model for users. Lambda’s pricing model primarily depends on the number of requests, allocated memory for the function, and duration, the time it takes to execute the code. Once the function starts to execute in response to an event or a invoke call, Lambda will start the timer. Then it measures the code execution time and rounds it up to the nearest 100 milliseconds.
No server management
Developers could write the function code directly in the Lambda console or upload it to AWS Lambda as a zip file or a container image. Once the developers add the code to AWS Lambda, it encrypts the code and stores it in a private Amazon S3 bucket. Then, AWS Lambda will provision and manage the compute infrastructure on behalf of the developers. This approach gives developers more time to focus on business logic and product innovation.
Automatic scaling
Since the function code is written in a stateless style, AWS Lambda could create any number of copies of the function and run them in parallel. In case of a large volume of events, Lambda will automatically scale the application by running many copies of functions to respond to each event. Therefore, the size of the workload doesn’t affect the performance.
Lower cost
AWS Lambda’s pay-per-use pricing model allows users to pay only for the compute resources that they use. When calculating the price, the Lambda rounds up the execution time to the nearest 100 milliseconds instead of the nearest hour. It will help organizations minimize operational costs.
Reference:
https://aws.amazon.com/lambda/
Serverless Architectures with AWS Lambda - Awsstatic