5 minutes serverless Practice | Building a server-free image Yellow Web application

Source: Internet
Author: User
Tags hosting web hosting website hosting

What is serverless?

Serverless Chinese as a "no server", dating back to 2012 Ken Fromm published "Why the Future of software and Apps is serverless", he described a scenario, from the user's own maintenance of the physical machine, To IaaS, to PAAs, the transformation of the computational paradigm does not stop, and when the cloud infrastructure matures, the application can take care of the presence of the server, and no server computing allows developers to build and run applications and services without regard to the server.

In 2016, Mike Roberts, in Martin Fowler's blog, serverless architectures, divides the serverless architecture into backend as a Service (BaaS) and functions As a Service (FaaS).

Baas is the backend as a service, that is, the application architecture is organized by a large number of tripartite cloud services and APIs, so that the logic and state of the server in the application are managed by the service provider. For example, a typical single page application (SPA) and mobile app these rich client applications, the front and back end of the interaction mainly with rest API calls mainly, only need to invoke the service provider's API to complete the corresponding functions, such as authentication, data access and so on.

Faas can be called function-as-a-service, developers can directly deploy the service-side business logic code, run in a third-party provided by the stateless computing container, developers only need to write business code, no attention to the server, and code execution is triggered by the event.

A serverless application is such an application that combines Baas and Faas, the user focuses on the application's business logic code, runs it on the Faas platform as a function of granularity, and integrates with the Baas tripartite service, and finally builds a complete system, The entire process does not need to focus on the server.


Advantages of serverless

1. No Management Server required
Developers need to focus on the business logic of the application, without having to focus on the presence of the server, lowering the threshold for access to the business, quickly coming online, and improving development and operational efficiencies.

2. Flexible expansion, pay on demand
According to Gartner and McKinsey, the average server CPU utilization in the world is only 6% to 12%, and the resource utilization of a large number of applications is very low, especially for applications where the load peaks and troughs are obvious. The serverless can be flexibly scaled according to the load, and pay on demand, according to the actual operation of the consumption of resources, and the business is the function of the granularity of operation, can make full use of debris resources, greatly reduce operating costs.

Function Workflow Functiongraph
After a brief introduction to the serverless architecture and its merits, let's introduce the function workflow (FUNCTIONGRAPH,FGS) of Huawei Cloud.

Function Workflow (FUNCTIONGRAPH,FGS) is an event-driven, function-managed computing service with managed functions that operate in a millisecond-scalable, operation-free, high-reliability manner. With a function workflow, developers do not need to configure and manage servers, simply focus on business logic, write function code, build applications in a server-less way, and then develop a resilient, highly available backend system that is billed for the resources consumed by the actual run. It greatly improves the efficiency of development and operation, and reduces the operating cost.



Building a server-free image Yellow Web application
To give you a more intuitive understanding of the serverless architecture and function workflows, we'll show you how to quickly build a complete, server-less picture-based Web application with a function workflow, such as receiving images uploaded by the user, and analyzing the image to determine if it's XXX. Click here to experience demo for free

Imagine, if we develop this application through traditional patterns, how do we need to develop it?

Even based on the current cloud platform, we still need to buy cloud server, focus on its specifications, mirroring, network and other indicators of the selection and operation, and then in the development process may also need to consider the integration with other cloud services issues, so that the code is coupled with a large number of non-business code, and the server and other resources are not on demand, May result in a lot of extra expenses.

Now we can quickly build this system with a function workflow service, without having to focus on the server and running on demand,

Create a function, call the Huawei Cloud Content detection service in the function to provide the image of the yellow interface, to achieve the image of the yellow function, and to configure a Apig trigger for the function, to provide the image of the yellow API, so as to build a complete picture of the Yellow no server backend. The static resources of the Web pages are then deployed in the Object Storage Service (OBS), where the user can access the front-end pages directly from the OBS. When the user uploads the picture, the page calls the image Yellow API that was built, and he automatically triggers the function execution, and the developer's function simply implements the logic of how to handle the picture after receiving the image (invoking the Content detection service), and finally returning the result to the front page. At this point, we have built a complete server-free image yellow Web application.

Now, we'll show you how to build this server-free application end-to-end.



Back-End API Setup
Enter the function Workflow service function creation page and select the picture yellow template. The template already provides the code for the function in this application, after creating the function as indicated in the code comment, the backend system of the application is successfully built, and the Apig trigger created for the function provides an HTTP (s) API to invoke the backend function, which is called by the external system, such as the front-end page.

The URL of the API after the successful creation can be seen in the "Triggers" section of the Function Details page:



Front-end Page Setup
There are many forms of front-end, here we provide a front-end code package for everyone to learn the reference, you can deploy this code package to OBS, quickly build a single page Web application (SPA). Then call the previous step back-end to provide the interface, connected back-end system, complete the entire service-free image Yellow Web application construction.

1. Download the code package and unzip it

2. In order for the front-end page to access your function, you need to configure the URL of the page rest request. Change the value of Checkimage in the/functiongraph/assets/config/apis.json file in the code package to the Apig trigger URL created in the previous step backend API build, which is the access address of your backend API.

3. Hosting front-end pages via OBS. Enter the object storage service, create an obs bucket, and upload the package files to the bucket one at a time. Because the files are much more, we recommend that you download the OBS Browser before you use OBS Browser to obtain an access key.

4. Start the website. Go to the static web hosting interface of the bucket, click Static website hosting, configure the bucket default home page for index.html

Once the configuration is complete, you have successfully built the front-end system for this case. You can access your front page through the access address provided by OBS, and when the image is detected, the page sends a request to your function.

Summarize

By building a complete, server-less image with the above end-to-end Web application, we can see that the serverless architecture has the following advantages:

1. No need to focus on any server, just focus on the core business logic, 5 minutes to quickly build back-end systems and online, greatly improving the development efficiency.

2. Function runs with the volume elasticity, pay on demand, when the created function is not executed, regardless of the fee.

3. With simple configuration of connected function workflows and other cloud services, even cloud services and cloud services, such as simply creating a apig trigger in this example, you can complete the connection of the API gateway and the function workflow, and then invoke the authentication yellow interface of the content detection service in the function. Then the function connects two cloud services together like a binder.

5 minutes serverless Practice | Building a server-free image Yellow Web application

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.