Through the development process of Serverless and the challenges brought to us, it leads us to change our thinking, simplify complexity, seek advantages and avoid disadvantages, make better use of its advantages, release enterprise efficiency, and bring infinite possibilities for creation.

A summary of Serverless

In recent years, both serverless computing and cloud native computing come into being in the context of the Internet. As its name implies, it means that developers do not need to manage servers and other infrastructure resources when building and running applications. Applications are decouped into fine-grained functions, which are the basic units of deployment and operation. Users only pay for the resources they actually use. This code is entirely event-triggered, and the platform automatically adjusts service resources in parallel to the request, with almost unlimited capacity to expand, with no resources running when idle. Code running stateless, can easily achieve rapid iteration, rapid deployment.

1.1 Serverless background

  • Cloud computing evolution history

In the era of rapid development of the Internet, from the initial physical server, to virtual machines using XEN, KVM and other virtualization technologies, and then to cloud computing automatic management of these virtualized resources, and then to the emergence of container technology, isolated applications about the operating system, now, we have Serverless, Technology that allows users to Focus on business logic without caring about the environment, resources and quantity of the application.

Cloud computing has evolved from IaaS, PaaS, SaaS, to the latest BaaS, FasS, Serverless in this trend.

  • The composition of Serverless

For a complete application, to Serverless, we need to consider the front-end, API grid, that is, back-end services and object storage database, etc. From the technical point of view, Serverless is the combination of FaaS and BaaS.

FaaS (Function as a Service) is a platform for running functions, such as Function calculation of Ali Cloud and Lambda of AWS.

Backend as a Service (BaaS) is back-end cloud services, such as cloud databases, object storage, and message queues. With BaaS, we can greatly simplify our application development.

Serverless can be understood as running in FaaS, using functions of BaaS.

1.2 Serverless characteristics

  • Stateless: But it also determines the stateless nature of Serverless, because each time a function is executed, it may use a different container and cannot share memory or data. If you want to share data, you can only use third party services such as Redis, COS, etc.
  • No O&M: With Serverless, we do not need to care about servers and O&M. This is also at the heart of Serverless’s thinking. The development of operation and maintenance has experienced human operation and maintenance, automatic operation and maintenance, DevOps, AiOps, etc. Serverless brings a new operation and maintenance mode, in which the only thing users need to manage is Code, which can be considered as NoOps.
  • Event-driven programming: Serverless’s run-time computing means that it is event-driven computing.
  • Low cost: operation cost. Serverless entrusts users’ servers, databases and middleware to BaaS/FaaS. Users will no longer participate in the maintenance of infrastructure and software, especially in large-scale cluster operation, the cost is greatly reduced. Compared with IaaS or PaaS servers or operating systems, Serverless allows users to operate servitized components, such as storage services and authorization services, which can shorten development cycle and reduce development difficulty.
  • On-demand charging: Different from IaaS or PaaS, Serverless/FaaS preallocates computing resources based on request times and runtime. On the one hand, on-demand charging can maximize resource utilization and reduce user resource costs. According to statistics, typical servers in commercial and enterprise data centers provide only 5% to 15% of the average maximum processing power output, which is essentially a waste of social resources. In the Serverless architecture, the provider provides finer computing power to maximize real-time requirements and greatly improves resource utilization. Therefore, it can be considered as “green” computing compared with IaaS and PaaS Serverless/FaaS.
  • Elastic scaling: One of the obvious advantages of the Serverless architecture is that “horizontal scaling is fully automated, elastic, and managed by the service provider.”

Challenges brought by Serverless

2.1 Service Transformation

  • Limited use scenarios: Serverless is not suitable for all scenarios. In the current development situation, Serverless is suitable for event-driven asynchronous workflow. If the application scenario does not adapt, it is very difficult to transform, and it is difficult to achieve results in the later stage.
  • Development and deployment: At present, Serverless ecosystem is in the stage of rapid development. At present, every major public cloud manufacturer has its own Serverless products. In order to facilitate the rapid development of developers, manufacturers have written various IDE plug-ins for their products, which can automatically complete, code detection, and can be automatically deployed to the cloud with one click. But for the coverage of some traditional applications, there are still a lot of places to continue to optimize and improve.
  • Running test: For function test, currently each major public cloud also provides running test cases, but there is no good function support for multiple interface parameter transfer, and it is also very troublesome to integrate the deployment node into CI

2.2 Infrastructure challenges

  • Underlying infrastructure build maintenance: currently for open source Serverless, for example: Knative Openfass/Kubeless or OpenWhisk for its construction, maintenance of deployment has been late, great challenges for companies, if the business migration, infrastructure layer problems, needs to be repaired in a short period of time, and puts forward very high requirements on operations staff.
  • API maintenance: There is no unified management and control platform for the service migration to Serverless and for the maintenance of a large number of back-end APIS in the later period, or maintenance tools are extremely difficult to manage. For the late maintenance of API, it is not only from the unified warehouse, but also needs to extend the control to the platform.
  • Related ecological maintenance: For Serverless is not only a single function at the back end, but also includes Baas related products. If enterprises choose open source tools by themselves, they need to maintain API gateway, object storage, logging, monitoring and so on, which need to be realized by users themselves. This entry into Serverless is like the sea, not only does not reduce user costs. It creates even greater technical challenges.

Overview of AWS Lambda

In view of the above challenges facing Serverless, we need to clearly recognize whether the known business applies to the Serverless scenario, split the business, and whether certain interfaces and certain module functions can be transferred to Serverless to optimize the architecture.

For infrastructure challenges, in the current public cloud phase of rapid development, it provides us with a unified “one-stop” work style on the experience of cloud, and best practices, or within the range we consider possible problems in the future, have to consider and solve for us, really realize the let us in the era of cloud computing, all users will be focused on in their business innovation, To release greater business value, here we carry out the practice of AWS Lamdb.

3.1 Overview of AWS Lambda

  • What is AWS Lambda

AWS Lambda is a computing service that lets you run code without pre-configuring or managing a server. AWS Lambda only executes your code as needed and scales automatically, from a few requests per day to thousands per second. You are only charged for the calculated time consumed – there is no charge when the code is not running. With AWS Lambda, you can run code for almost any type of application or back-end service without any management. AWS Lambda runs your code on a high-availability computing infrastructure and performs all the management of computing resources, including server and operating system maintenance, capacity provisioning and automatic scaling, code monitoring and logging. You only need to provide your code in one of the languages supported by AWS Lambda.

  • Serverless ecological

AWS Lambda belongs to FaaS, and Serverless also needs related services of Baas. Public cloud provides us with a complete set of solutions, such as event response, changing data in Amazon S3 buckets or Amazon DynamoDB tables. And using the Amazon API Gateway to run code in response to HTTP requests; Or use API calls made through the AWS SDK to call your code. With these capabilities, you can use Lambda to easily build data-processing triggers for AWS services like Amazon S3 and Amazon DynamoDB, process streaming data stored in Kinesis, or create your own backend that runs on AWS scale, performance, and security.

For DevOPS, you can deploy these applications automatically using CodePipeline and AWS CodeBuild.

3.2 Application Scenarios

Serverless has certain application scenarios. Analyze its own service architecture, that is, scenarios, and disassemble or migrate services adapted to the scenario to Serverless based on the characteristics of Serverless.

  • Custom picture shop for commodity picture maintenance, according to the location of the display of goods, the picture will be dynamically cut into different sizes, or hit different watermarks. When the store uploads the image to the object storage OSS, the function calculation will be triggered by a custom trigger on the function calculation. According to the calculation rules, different sizes of pictures can be generated to meet the needs of online commodity display. The whole process does not need to build additional servers, nor does it need the intervention of website artists.
  • Low-frequency request in the Internet of Things (iot) industry, iot devices transmit a small amount of data and usually transmit data at a fixed interval, so low-frequency request scenarios are often involved. For example, iot applications only run once per minute for 50ms, which means that CPU usage is only 0.1%/ hour, or 1000 identical applications can share computing resources. In the Serverless architecture, users can purchase 100ms resources per minute to meet computing requirements, which can effectively solve the efficiency problem and reduce the cost.
  • Custom events When a user registers, the user sends an email to verify the email address. Customized events can also trigger the subsequent registration process, without the need to configure an additional application server to process subsequent requests.
  • Fixed time trigger Event This event is triggered at a fixed time. For example, transaction data in busy hours is processed at night or in idle hours, or batch data is run to generate data reports. Serverless mode eliminates the need to purchase additional processing resources that are not highly utilized.

AWS Lambda practice

You will create a Lambda function using the AWS Lambda console. Next, you will manually invoke the Lambda function using the sample event data. AWS Lambda will execute Lambda functions and return results. Then, you will verify the execution results, including the logs created by your Lambda function and various CloudWatch indicators. Due to the limited space, I will practice the basic use of Lambda here. Later advanced parts can be stored on the official website to enjoy one-stop service experience.

4.1 Creating a Function

Open the AWS Lambda console and select Create A Function. In the function name, enter the function name and select Create Function.

4.2 Designing Functions

The designer displays an overview of your functions and their upstream and downstream resources. You can use it to configure triggers, layers, and targets.

  • Create a function

Here we create a function for the Python 3.6 interpreter runtime.

Once created, we can see the code for the function template:

import json

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }
Copy the code

When you’re done, you can see the function we wrote.

4.3 Running Tests

Click Test to create a test event, select a simple Hello World test template, name it, and test it.

After the test event is created, run the test and you can see the structure of the run.

Note: Each user can create up to 10 test events per function. These test events are not available to other users.

4.4 Configuration Details

We can start by looking at the results of running the test.

By printing the results, we can draw the following configuration conclusions:

  • Lambda_handler: This function is the function that lambda runs every time. All of our business logic is written inside this function.
  • Event: is the data we need to process, that is, the input parameter.
  • Context: provides information about the function. For example, aws_request_id indicates the requestid generated after the function is called, and function_name indicates the function name.
  • At the end we can use functions to return results and so on.

4.5 Log Monitoring

4.5.1 Viewing Logs

After the function test runs, we can view the information about the function running by monitoring the log.

  • Execution result: The section displays the execution status as Succeeded, as well as the result of the function execution returned by the return statement.
  • Summary: Part displays the key information reported in the Log Output section (the REPORT line in the execution Log).
  • Log output: Sections show logs generated by AWS Lambda for each execution. These are logs written to CloudWatch by Lambda functions. For your convenience, the AWS Lambda console displays these logs for you.

4.5.2 Viewing Monitoring

For function operation monitoring, we can check it through CloudWatch. Later, we can conduct statistical analysis and tune the bottleneck and concurrency of the function.

4.6 Clearing Resources

After the function is used again, clear related resources. Log and IAM roles must be cleared during resource clearing.

  • Delete lambda functions

  • Deleting a Log Group

  • Deleting an Executive Role

This completes the cleanup of the entire function, role, and log group.

4.7 Precautions

  • Concurrency: When the function code is running, if there is another request, the function needs to be configured and reconfigured, preconfiguring another instance to improve the concurrency of the function. Concurrency is constrained by region-level restrictions
  • Trigger: Is a resource or configuration that calls a Lambda function. This includes AWS services that can be configured to invoke functions, applications that you develop, and event source mappings. An event source map is a resource in a Lambda that reads items from a stream or queue and invokes functions.
  • Virtual Private Cloud (VPC) – If your function needs to access resources that cannot be obtained on the Internet, you need to connect the function to the VPC to obtain resources on the Internet.
  • Sensitive data can be injected into a function through environment variables to ensure the security of the function.

Five thoughts on Serverless

With AWS Lambda, you are only responsible for your own code. AWS Lambda manages a cluster of computers that provide memory, CPU, network, and other resource balancing. Function to calculate the applicable to many scenarios, but it is not cover all scenarios of tiger balm, no server cloud late function to the development of faster, the need for the business logic of the fine comb and each function call, you need the cloud vendors more personalized custom services, have they need to improve the ecological, at least no cloud server function supports various products on their own cloud. Although Serverless still has many limitations at present, Serverless has been developing and improving, and the majority of developers and service providers are looking for the infinite possibilities of Serverless.

🏆 issue 7 | all things can be Serverless technology projects