Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the developer tools of Serverless

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use Serverless developer tools. I hope you will get something after reading this article. Let's discuss it together.

Challenges for Serverless Development

From a developer's point of view, Serverless development has changed a lot compared with traditional development methods. Developers are used to local development, debugging, testing and continuous integration, continuous deployment and other processes, when developing for Serverless, there will inevitably be a lot of questions:

How to develop a Serverless project locally?

How to debug the Serverless function locally?

Can the logs printed during development be easily retrieved and used in debug?

How to ensure the consistency of the local environment and the cloud environment?

How to publish multiple functions to the cloud environment at one time when publishing?

Serverless-oriented tool Construction Logic

Faced with various challenges in the development process, developer tools will make Serverless project development closer to users' habits from the perspective of developers.

The following is a life cycle flow chart of project development, you can see that in the project development process, you have to go through at least several stages such as requirements, coding, building, testing, release, deployment and operation and maintenance.

In the coding and construction phase of the code, the automatic construction of the code is completed through continuous integration, which is called continuous integration CI (Continuous Integration). In the code release and deployment phase, the continuous delivery CD (Continuous Delivery) of the code can be completed by configuring grayscale policy, alarm and rollback plan, etc.

In addition, in the development process of developers, they will also encounter scenarios such as coding, debugging and unit testing, integration testing and so on. The support of these functions is also an indispensable part of the development for Serverless architecture. The construction of developer tools will focus on solving the pain points throughout the life cycle.

Developer tools for Serverless

Today, with the hot trend of Serverless technology, many solutions and tools for developers have emerged, such as open source Serverless Framework,Zappa and ClaudiaJS.

Most developer tools encapsulate the underlying capabilities by calling the API/SDK of Serverless products from cloud vendors, and provide customers with a more intuitive and convenient way to use them. At present, the common development tools are mainly divided into two forms: CLI command line tools and IDE plug-ins. Although the presentation is different, it essentially lowers the threshold for local development of Serverless projects and encapsulates more ways of organization and orchestration based on the basic capabilities provided by the cloud platform.

This article will take Tencent Cloud's Cloud function as an example to introduce the more typical development tools-Tencent Cloud Serverless local development tool and VS Code plug-in.

Tencent Cloud Serverless Local Development tool (SCF CLI) is maintained in the form of open source projects to make it easy for users to package, deploy and debug functions locally, as well as to generate cloud function projects and further develop based on demo projects. SCF CLI completes the description of the function and related surrounding resources through a function template configuration file, and implements the process of local code and configuration deployment to the cloud based on the configuration file.

Let's take a Serverless project as an example to show the process of using Serverless development tools:

1. Function development and coding

First, after SCF CLI is installed and configured, you can view the supported commands with the-- help command, and then quickly generate a function demo through the scf init command. After the creation is complete, you can see that the index.js file and the template.yaml file are generated.

Among them, index.js is the entry file of the function, and tempate.yaml records the configuration information of the function through a specific format, such as memory size, timeout and other information. Tempate.yaml is also the key to the subsequent orchestration and organization of functions. In addition to simple init commands, SCF CLI also supports pulling substitution codes from git and some existing function templates to facilitate rapid development based on specific scenarios.

2. Code debugging

In the development process, developers will choose their own familiar IDE code editor to write code. To facilitate local development and debugging more quickly and intuitively, one-click debugging is supported through the Tencent Cloud VS Code plug-in.

First, you can open the file directory where you just created the function, and the function is automatically recognized in the plug-in. After that, you can make a breakpoint through F9, and F5 can start the debugging capability. The output of the function debugging process is printed in terminal and supports single-step debugging to view variables, stacks and other information.

3. Code release

After completing the development and testing, you can also release the code through the VS Code plug-in or CLI, respectively. Currently, it supports packaging and publishing of zip, uploading and publishing through COS (object Storage), and publishing through git repository. Only files with incremental changes are submitted each time. After the release, you can also view the health status and return logs in the cloud through cloud debugging in the plug-in.

4. Multi-function deployment

In VS Code plug-ins and CLI, you can easily deploy a single function to the cloud, so what should you do if you want to quickly publish multiple functions?

At present, it can also be achieved directly through the deploy command of SCF CLI. You only need to maintain the information of multiple functions through a template.yaml.

In addition to publishing, you can also define the common configuration of some functions through the Global field in the template.yaml file, so as to solve the problem that multiple functions share the same pain points in the development process (for example, sharing the same environment variables, timeout and memory, etc., without repeated configuration)

For example, in my workspace, there are two functions "hellotinatest234" and "testscflinux" that need to be mass deployed and uploaded, and two functions use a common configuration. You can define the properties of the two functions in template.yaml, and define the Global field to specify the public configuration. The deployment process and the style of yaml are as follows:

5. Exception troubleshooting-logging capability

In addition to the development process, when the production environment is abnormal, you can also use CLI's logs-tail and other commands to query logs quickly and flexibly, and can be used with tools such as grep awk. When a new version is released, tail mode can be used to print cloud logs in real time, making it easy for developers to quickly view problems.

6. DevOps capability

Finally, the DevOps capability of SCF. Docking with Jekins,Coding and BlueKing platforms is already supported. And continue to do deeper integration of the Coding platform, providing DevOps capabilities that are available out of the box.

Summary and Prospect of developer tools

With the gradual improvement of the Serverless ecology, more and more scenarios can be covered by tools. For example, you can simulate API gateway requests locally, or perform unit tests and integrity tests on functions by integrating common testing frameworks. Developers also have more room to participate in building a Serverless-oriented development architecture.

Subsequent developer tools will focus more on the organization of functions and resources around functions (gateways, DB, etc.), starting from the project / application dimension, so that developers can quickly use tools to build a common usage scenario (such as WEB website, file upload tool, etc.), so as to better understand the organization of Serverless projects.

In addition, in the docking of continuous integration and continuous delivery, developer tools will also support more convenient and universal configuration, facilitate standardizing the development process, and host large projects and core businesses.

Serverless Framework 30-day trial Program

We invite you to experience the most convenient way to develop and deploy Serverless. During the trial period, related products and services provide free resources and professional technical support to help your business achieve Serverless quickly and easily!

For details, please refer to the Serverless Framework trial Program

One More Thing

What can you do in 3 seconds? Take a sip of water, read an email, or deploy a complete Serverless app?

Copy link to PC browser access: https://serverless.cloud.tencent.com/deploy/express

Deploy quickly in 3 seconds and immediately experience the fastest Serverless HTTP development in history!

Portal:

GitHub: github.com/serverless

Official website: serverless.com

After reading this article, I believe you have a certain understanding of "how to use Serverless developer tools". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report