Web framework master Serverless technology

This article will take you to learn:

• Master the concept and architecture of Serverless
• Master the operation and process of Alibaba Cloud function computing products
• Deploy popular web frameworks to Alibaba Cloud function computing platforms
• Use the serverless Devs client local deployment method
• Create your own Web IDE application

Learning items:

1. Difficulty: Introduction
2. Prerequisite: Create your own Alibaba Cloud account
3. Duration: 60 minutes
4. Enter Alibaba Cloud Lab:

https://developer.aliyun.com/adc/scenario/fa580ae836224ba6947fc5ec327e4ba1

Serverless related concepts&practices

, duration 05:17

• Evolution from Serverless;
• Advantages of function calculation;
• Learn about Serverless from three aspects of the application scenario.

Note: Alibaba Cloud functions used in this experiment calculate FC. Object storage OSS is a traffic product and domain name service is a pre purchased product. There will be traffic costs and purchase costs. Please use it carefully according to your own conditions. Please bear the expenses incurred. Of course, it can also be used purely for reading and learning.

Serverless evolution

Serverless, what exactly is Function Compute?

Serverless, also called serverless. Serverless emphasizes an architecture idea and service model, so that developers do not need to care about infrastructure (servers, etc.), but focus on the application business logic. Serverless is also the next generation computing engine. For example, the Serverless products of Alibaba Cloud platform mainly include AliCloud function computing FC, Serverless application engine SAE, and Serverless workflow. So you can understand that Serverless is an architectural idea.

I think the core of Serverless is function computing, which is an event driven fully managed Serverless computing service. You don't need to manage the server and other infrastructure, just write code and upload it. Function computing will prepare computing resources for you, and run your code in an elastic and reliable way.

The cloud function is usually referred to as Serverless.

At present, the popular application architectures of the Internet are mainly from single architecture to popular microservices, and now the rapid development of Serverless architecture. Some characteristics of the three architectures can be seen: high coupling degree, elasticity and poor expansibility of single frame; Microservices are much improved and more flexible, but the cost of operation and maintenance learning is also high.

Serverless features elastic high availability through event driven mode; Including payment on demand; Operation and maintenance free are its strengths. I believe that with the continuous development of technology, Serverless must be a very popular technology architecture in the future.

From the official introduction of Alibaba Cloud, we can see the different forms of Serverless for different scenarios. With the emergence of standard FaaS templates and paid customized FaaS templates, I believe they will also gradually develop. Maybe they will eventually be directly AI intelligent generation functions through low code configuration, which will let us wait and see.

Serverless Function Calculation Advantages

Operation and maintenance free: no need to manage server hosts or server processes.

Elastic scaling: automatic scaling and automatic configuration according to the load. The expansion range is zero to infinity.

Pay on demand: determine the actual cost according to the usage.

High availability: It has implicit high availability.

In addition, the cloud function cannot save the state, but it can be improved through other computing services. For example, Redis or local cookies can be used to save user state information.

One of the core advantages of Serverless is its rich elastic policies and flexible call policies. We can see from the figure that it can flexibly configure the basic indicators CPU, memory, instance upper and lower limits, etc.

AliCloud FC can combine most of the products and services of cloud computing at the same time, forming a very flexible, low coupling binding, ready to use. Called through events, http, and triggers. This official flow chart clearly illustrates the whole process of function calculation.

Serverless application scenario

Most industries can use the Serverless architecture. For example, games, online education, e-commerce, SaaS products, applets, etc. are strongly supported by core function computing and other Serverless products.

From here, we can understand the application details of function calculation in detail. If you are interested, you can save it.

Now let's talk about a simple Web site case. Many people have doubts. Cloud function is just a function calculation, equivalent to an API interface. What should I do if I want to combine database, storage and other functions?

From this simple structure diagram, we can see that the cloud function needs to cooperate with various cloud computing services to fully deploy our complex applications. We can speed up the presentation through CDN services and store file resources through OSS.

You can also understand that the cloud function deploys your website code, uses Redis to save the user's session state, and stores important data in MySQL or MongoDB, etc. If queue and log services are needed, we can quickly access them through the products provided by the platform, which can meet most common applications. Let's learn step by step.

Through practice, we learned what Serverless is, its advantages and application scenarios. The technical architecture of Serverless is still developing rapidly, and various cloud manufacturers are developing their own Serverless products.

If the above content is inappropriate, please comment and leave a message for me. Let's exchange and learn together. Next, let's learn how to deploy the popular Web architecture on Serverless.

Deploy Web framework to function calculation

, duration 07:48

In this part, we also learn from three aspects: first, we learn the product functions of function calculation; Then deploy the Web framework Spring Boot; Finally, practice the case of deploying Nodejs framework Express.

Alibaba Cloud function computing product features

Without further ado, what are the functions of Alibaba Cloud function computing?

Note: You need to log in to your Alibaba Cloud account to start the function computing service. The function computing service belongs to traffic billing and may incur traffic charges. Please use with caution. Please bear the expenses incurred, or simply read and study.

1. Log in to Alibaba Cloud's website, click the top to log in, and enter your user name and password.

2. Click the product in the upper left corner, find the Serverless category in the product service, click the function computing PC below, and then you can see the main panel of function computing. (If there is no subscription service, you can directly agree to subscribe.).

3. Next, learn to experience the product functions of function calculation step by step. The overview shows the call data and running environment of the overall function calculation.

Let's move on to the second application in the menu. I think this is a very good function, which greatly facilitates the threshold of users. We can quickly create our own sites and applications through this function.

The application includes two methods: template creation and warehouse import. Later, I will mainly demonstrate the case of template creation.

The warehouse mode can also be pulled from your Github/Getee and other common warehouses. I won't repeat it here.

What is service? Service is the unit of functional computing resource management. Before creating a function, you must first create a service. All functions under the same service share some of the same settings, such as service authorization and log configuration. Starting from the business scenario, an application can be divided into multiple services. From the perspective of resource usage, a service can be composed of multiple functions. For example, a data processing service is divided into two parts: data preparation and data processing. The data preparation function has a small resource requirement, so you can select small instances. The data processing function has a large demand for resources, so you can select large instances.

The resource scheduling and running of function computing are in function units. Functions must be subordinate to services. Multiple functions can be created under the same service. These functions share some of the same settings, such as service authorization and log configuration, but are independent of each other. This article describes the properties and running environment of functions, and how to create, configure, and delete functions through the function calculation console.

After creating a service, we can create a function below it. The specific code in the function is the implementation of your business scenario. From the standard runtime; Smooth migration of Web Server; Container image; Templates can be created in 4 forms.

What is shown here is the cloud function code of a lottery turntable that we wrote before. It mainly calls the cloud function through an applet, and then the cloud function calls MongoDB data. Because good concurrency is required when there are many lottery winners, we use MongoDB and cloud functions. It allows users to draw lottery without any stuttering, and also saves hardware costs when users are few. Cloud function meets our needs well.

Tasks are actually places to manage asynchronous functions. It provides a fully managed, out of the box, and observable friendly large-scale task processing platform. After you upload the code package/container image and create the task processing function, you can submit, view, stop and retry the task. You can also pause/resume the execution of processing functions. Click here for more details.

Advanced functions of function calculation mainly include monitoring, domain name, elastic management and layer management. As shown in the figure, the overall data is monitored.

It is easy to understand that domain names are bound to their own cloud function applications, which can be Web applications or API interfaces.

Elastic management is to configure the online use of cloud function resources to prevent excessive costs. At the same time, the minimum instance can be configured to reduce the number of cold starts.

Layer management provides a common dependency library, a running environment, etc. Functions can be shared before, reducing the volume of code packages.

The audit log, permission assistant, workflow and application engine function products in other more functions will not be elaborated here. Interested friends can try it when developing their own cloud functions.

1. What scenarios need to use a custom domain name?

When your function is triggered by HTTP request, you may need to use your own custom domain name to access your function. For example, if you create a function as a Web application and want users to access the Web application through a fixed domain name, you can bind a custom domain name to the Web application. In addition, you can also set the CDN acceleration function for the domain name, use the application deployed in function computing as the source station, and publish the source content to the edge node, so that the end user can quickly read the required content.

2. What is flexible management?

Function calculation provides you with two instance usage modes: volume based mode and reservation mode. You can configure the maximum number of instances to control the upper limit of resource usage of a single function, to prevent instance occupancy caused by excessive calls to a single function, to protect back-end resources, and to avoid unexpected expenses. At the same time, the reserved mode instance can be activated by configuring the minimum number of instances. The function computing system will use the minimum number of instances configured as the resident instance of the function to quickly respond to function call requests, reduce the number of cold starts, and provide better service response for delay sensitive online services. The billing methods of pay as you go mode and reservation mode are different.

3. What is a layer?

Layer can provide you with customized public dependency libraries, runtime environments, function extensions, and other publishing and deployment capabilities. You can refine the common libraries that function depends on to layers to reduce the code package volume during deployment and update, or you can deploy customized runtime to be shared among multiple functions by layers. By default, the layer is deployed in the/opt directory of the function execution environment as an additional code directory for functions. When the function configures multiple layers, the contents of these layers will be merged into the/opt directory.

So far as the product functions are concerned, you can understand and sort out the operability and characteristics of function calculation.

Deploy Web Framework Spring Boot

Note: You need to log in to your Alibaba Cloud account to start the function computing service. The function computing service belongs to traffic billing and may incur traffic charges. Please use with caution. Please bear the expenses incurred, or simply read and study.

Next, we will click "Application" in the menu on the left.

1. Click Application in the left menu, select Create Application through Template, and select Spring Boot Template. It is better to read the instructions in the following details carefully before creating.

2. Then click Create Now to enter the details page, where I choose to deploy directly.

3. The application name is selected by default, and then click Create.

We will see a process of creation. After creation, you can see that the framework has been generated. Is it very simple and stupid.

4. Click the domain name to see the website page. This is the home page of the generated framework. The cloud platform automatically configures a sub domain name for us.

5. Click View All on the above creation page to view the log information of the creation process.

The deployment is divided into four parts: front environment; Resource synchronization; Resource inspection; You can read the deployment carefully if you are interested in it, which is helpful to understand the overall process.

6. View the specific contents through the services and functions in the bottom function resource.

When you click the service web framework, you will jump to the specific service and function information. At this time, you can see that the Spring Boot framework created through the template has been deployed. If you are interested, you can view the framework code and modify the code.

At this point, we have fully deployed the Spring Boot framework to the function computing platform. You can experiment with it yourself.

Deploy Web Framework Express Case

Note: You need to log in to your Alibaba Cloud account to start the function computing service. The function computing service belongs to traffic billing and may incur traffic charges. Please use with caution. Please bear the expenses incurred, or simply read and study.

Continue to deploy the node The TodoList case of the js language Express framework. Or find the TodoList case of Express in the application.

Select a popular application, select the corresponding template case, and click Details.

We can read the installation instructions in the pop-up layer on the right. Remember that we don't need to click to create an application immediately here. We will go back to the local machine to create an application with the client.

This time, we use the open-source tool Serverless Devs to deploy applications locally. Before installing the Serverless Devs client, you need to have npm pre installed on your local machine, that is, you need to install Node Js environment. You can download node on its official website js:

https://nodejs.org/zh-cn

Be sure to select the default Paht to add to the global variable, and then open CMD to check whether the node installation is normal. Enter the following command into cmd.



node -v

The version number shown in the figure below is normal. If there are other problems, please install the npm package environment on your own Baidu.

1. Install Serverless Devs first. You can install it directly from the official document in the figure.

https://docs.serverless-devs.com/serverless-devs/install?spm

$ npm install @serverless-devs/s -gbr

The following represents successful installation.

Then we configure our own key through the command line. Click the avatar icon in the upper right corner of Alibaba Cloud for the key. In the pop-up layer, select "AccessKey Management" to find your own key and secret.

3. We open the cmd command prompt tool of Windows to configure the key, and enter the following command:

s config add

Select Alibaba Cloud according to the prompts, and then select Paste step by step. (Before entering the s command, remember to install the serverless Devs client according to the above instructions. No detailed instructions are given here.).

4. Initialize the template project, enter the following command, and you can see that the template has been downloaded to our local.

s init todolist-app -d todolist-app

5. Enter the local directory and deploy cloud services to the Alibaba Cloud function computing platform. Enter command:

cd todolist-app && s deploy

You can see on the left that the generated domain is the access domain name, and the trigger form is http. The name and configuration of cloud functions are clear at a glance. Here is a reminder that cloud functions deployed locally with client tools will not appear in the list of applications on the Alibaba Cloud platform.

6. After deployment, the generated domain name can be seen on the console, and the copied domain name can be accessed on the browser. This page will appear. If you modify the local code and then run the deployment command again, our Serverless application will be updated.

Back to the cloud platform, you can see the deployed services in the "Services and Functions" menu on the left. Click in to see the functions just described.

Well, do you think cloud function is not very difficult here. In addition, you should remember that if you only practice learning to deploy applications, you can delete the corresponding applications or services after learning to avoid additional costs.

In retrospect, the deployment of both frameworks has been completed, which is beyond imagination!

As a word, I'm still satisfied with Alibaba Cloud's function computing products, especially the online application of this function, which makes it easier for beginners to learn and deploy.

In the above article, I learned how to deploy Web applications to function computing platforms.

Make Web IDE

, duration 03:19

Next, I will teach you how to deploy your own Web IDE tool, including how to configure the officially generated domain name into your own domain name.

Introducing Open Source Web IDE Tools

Before practice, let's briefly understand this Web IDE tool. It is a lightweight Web IDE service based on Serverless architecture and Vscode that is ready to use and ready to go. A large number of plug-ins; Real time data storage; Low cost.

It uses golang language to realize reverse proxy access. It is based on open source openvscode server and provides the function of vscode Web IDE. If you are interested and know Golang well, you can learn about local debugging methods.

Through the basic process, we can learn the operating principle of this open source tool, which is convenient for debugging and secondary development.

The focus here is on development and debugging. If you need to build in the local environment, you should carefully read here to understand the directory structure and related configuration information.

After the introduction of open source tools, let's strike while the iron is hot!

Make your own Web IDE tool

To start making your own Web IDE tool, follow the steps below step by step.

Note: You need to log in to your Alibaba Cloud account to start the function computing service. The function computing service belongs to traffic billing and may incur traffic charges. Please use with caution. Please bear the expenses incurred, or simply read and study.

1. Find the template of serverless vscode webide from the official template, and click Create Now.

Note: OSS service of object storage belongs to traffic billing and will incur traffic charges. Please use it carefully, and bear the cost if any. Of course, you can also simply read and learn. It should be noted that this web ide tool needs to create OSS object storage, which is convenient for storing user data. When creating an application, click Create New OSS Bucket, jump to the OSS product, and directly create an OSS Bucket. Click Create New OSS Bucket under the red box.

2. Jump to the OSS product page, click the bucket list on the left, click Create Bucket, fill in a name webidepractice, and click Save.

You can also create OSS buckets in advance through this link.

https://oss.console.aliyun.com/overview

3. Return to the application creation page, click Refresh, and select the OSS you just created. Remember that the cloud function and OSS need to be in the same region. After the creation is successful, it will appear in the application list.

4. Click the configuration in the above figure to see the following page to understand the configuration of the following function. The red box shows the OSS we selected, which can also be adjusted to suit your own configuration.

5. Click the access domain name in the list to see the Web IDE tool. You can open the code on the Github repository here and directly write programs online. Is it very convenient.

6. Configure your own domain name (if you have not purchased an Alibaba Cloud domain name, you can ignore the following).

Note: You need to purchase domain names from Alibaba Cloud platform, and domain names will be charged. Please use it carefully, and bear the cost if any. Click Domain Name Management in the left menu, click Add Custom Domain Name, and you can see this page. Configure the sub domain name here, copy the public CNAME domain name, and click the cloud resolution DNS console to configure the domain name.

7. Click the cloud resolution DNS console and jump to the domain name resolution product page. Select the domain name you purchased. In domain name resolution, click resolution settings to configure the CNAME of the public network.

8. Add a subdomain name record of the IDE's cname. The record value is copied from the cloud function, thus forming a mapping relationship. After adding, we return to the cloud function domain name configuration page just now, select the corresponding routing configuration, select the service name, function name, and version name corresponding to your domain name, and click Create to complete the task.

9. Then enter your domain name in the browser, and our Web IDE tool appears. Do you feel a little excited here.

At this point, we have learned to make our own Web IDE tools. Interested friends can develop and improve their own online tools for the second time.

All learning and practical knowledge in this practice have been finished. To review the overall knowledge, from understanding the concept, architecture and application scenarios of Serverless, to learning the products of operating function computing, to deploying popular Web frameworks, we also made a Web IDE tool of our own.

I believe that for an entry-level learner, you can follow me to learn and practice, which proves that you have basically mastered Serverless. Later, you can migrate and deploy your products, or develop and deploy your own new projects or products in function computing.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us