Serverless landing practice

Architect advanced Club 2021-10-14 06:44:17

.Net Core Serverless First experience

What is? Serverless

Serverless It's a relatively new topic in today's software world . It doesn't have a universally accepted definition of authority , Everyone and every enterprise may interpret it differently , and Serverless It is in this situation that the development of . But even so , Somewhat Serverless It's still widely recognized :

  • The host and process of the server are completely managed by the supplier

  • It can automatically scale according to the load

  • Charge according to the exact usage , Like water and electricity .( Utility calculation )

Quote Nuggets , Original address :


Serverless evolution



In this development process, there are several gradual milestones :

  • Virtualization technology is used to virtualize large physical machines into a single VM resources .

  • Move virtualization cluster to cloud computing platform , Just do simple operation and maintenance .

  • Take every one. VM According to the principle of minimizing the running space, it is divided into more detailed Docker Containers .

  • be based on Docker Container building does not manage any running environment 、 Just write the core code Serverless framework .

Quote alicloud , Original address :


Alibaba cloud Serverless -  Function calculation

Function computing is an event driven fully managed computing service . Use functions to calculate , You don't need to purchase and manage infrastructure like servers , Just write and upload the code . Function calculation is ready for you to calculate resources , Run tasks flexibly and reliably , And provide log query 、 Performance monitoring, alarm and other functions .

With the help of function calculation , You can quickly build any type of application and service , And just pay for the resources actually consumed by the task .

Quote alicloud , Original address :


To write .Net Core Code

1. Create a new one .net core Console program , It's called AliyunServerless.



2. Reference the function calculation component provided by Alibaba cloud Aliyun.Serverless.Core

 Install-Package Aliyun.Serverless.Core


3. Write according to the requirements of function calculation .Net Core Class and function of , Here are two classes and functions

a. Print execution log

 /// <summary>
/// Print execution log
/// </summary>
public class LogHandler
public void Handle(Stream input, IFcContext context)
ILogger logger
= context.Logger;
"Handle request: {context.RequestId}");


b.  Print server IP

 /// <summary>
/// Print server IP
/// </summary>
public class IpHandler
public void Handle(Stream input, IFcContext context)
ILogger logger
= context.Logger;
var ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
"Handle request: {context.RequestId}");

foreach (var ipAddress in ipHostInfo.AddressList)
"IP Address:{ipAddress}");


explain :

  Please refer to the original address for details :


4. Release the program and package it into zip

 dotnet publish -c Release



Configure Alibaba cloud function computing

1.  Fee description and free quota


2. Select the region where the function executes

Refer to the entry address :



3. Create services and functions

a. Create a function



b. choice “ Event function ”, then “ next step ”


c. Configuration function information


among :

“ The service ” It's grouping , Fill in as needed .

“ The name of the function ” Is the name. , Fill in as needed .

“ Running environment ” choice dotnetcore2.1.

“ Function entrance ” Fill in... As required , The template is { Assembly }::{ Namespace }.{ Class name }::{ Function name }, Here is :AliyunServerless::AliyunServerless.LogHandler::Handle

“ Function execution memory ”, Memory required for function execution .

“ Timeout time ”, Function execution cannot exceed the set time .

d. Execute function

Click on “ perform ”, You can see the executive summary ( execution time 、 Using memory 、 Execution status, etc ) And implementation results :


e. Create trigger


It's used here “ Timing trigger ”, Support Cron expression , The highest scheduling frequency is 1 minute , Second level scheduling is not supported ; except “ Timing trigger ”, There are also the following trigger types :

  Interested friends can do their own research .

  After the trigger is configured , The function will be triggered by timing , Because here is the print log , You need to configure the log to see , No log is configured in this article , Don't show the trigger effect .


Extended testing

Follow the steps for creating functions , establish “ Print server IP” function , Execute and track , give the result as follows :

1. Multiple execution (5 Different times RequestId), The server IP It hasn't changed ( All for, Description assign to the same server



2. Re upload package , The server IP Will change , But the same package server IP unchanged

a. First time upload again :



b. Second upload :


3. My choice of execution area is “ south China 1( Shenzhen )”, But the server IP Is the U.S. IP; Because there's no server information , This conclusion is only for reference


4. Call statistics will be non real time ( Normal phenomenon ), Most business months should be free enough to use


Source code address

Please bring the original link to reprint ,thank
Similar articles