Serverless practice series (X): New command-line tools to help you quickly deploy cloud function

SCF CLI Tencent and so on function (Serverless Cloud Function, SCF) products command-line tool must have a lot of small partners already know, or after a trial. As a developer tool that can improve efficiency, Tencent cloud Serverless team has been optimized to work on the SCF CLI, this article will introduce you to the new SCF CLI increase of interesting features !


 

Introduction

A, Deploy function optimization

1: Deploy can select the default COS

Just set the time, using-cos will be provided, of course, also be scf configure set --using-cos y directly set:
640?wx_fmt=png
Once selected, you can in the next deployment, the default upload code to your cos, faster deployment:
640?wx_fmt=png
Even if you set cos, when a particular Deploy, cos do not want to use, you can choose not to deploy by cos increase --without-cos:
640?wx_fmt=png
COS also want to customize can: - cos-bucket:

640?wx_fmt=png

(In the absence of this cos, so upload failed)

In everyday use, there may be deployment of the same piece of code.
For example, I deployed the code A, B and deployment of code. After that, I want to re-deploy the code A, according to the traditional method is to upload A code again, but if Package is relatively large, it is more uncomfortable. The new version of the CLI through Package testing, 130M for the first time deployed using 25s, a second deployment of the same file, only 2s.

Attached: COS-related billing Links

  • Free credit:

https://cloud.tencent.com/document/product/436/6240

  • Billing Summary:
https://cloud.tencent.com/document/product/436/16871
  • Accounting method :
https://cloud.tencent.com/document/product/436/36522
  • Product Pricing
https://cloud.tencent.com/document/product/436/6239

2: Deploy version history

Code deployment, if problems arise, the need to restore the version history. The new version supports the deployment of SCF CLI version of history, after you use the using-cos, version history can be deployed by the parameters --history deploy:
640?wx_fmt=png
Select a historical version, you can directly implement document rollback:
640?wx_fmt=png

3: Packaging optimization function

All files are packaged under the old version will SCF CLI user directory, the new SCFCLI in this respect also made a key optimization, you can specify the ZIP directly, specify a file, and packaged by default when removing the .git and other hidden directory, and after deploy before deleting the default package information.
Yaml file can be:
640?wx_fmt=png

Second, the new Delete function

Older SCF CLI does not support the Delete function in the new version, you can comfortably use:
640?wx_fmt=png
Just enter scf delete --help you can see the use of methods and parameters described in Oh!

Third, the new List function

In the past, if you want to view the contents of the cloud function, or what I deploy function, is the need to go to the console area one by one, one by one namespace view. Now without cumbersome, can be realized by List command:
640?wx_fmt=png
The same can view all usage by the SCF --help: scf list --help

Fourth, help optimize document

Many of the above description, so that we are using the --help to view the help, then in the new version - which has a big help to optimize it - global optimization help document, you can view the help in any --help command :
640?wx_fmt=png
In the instruction pages can be an example to look at:
640?wx_fmt=png
Each main instruction, instructions will be described using examples and, while the specification is described parameters.

Five, API Gateway section

Existing SCF CLI always need when using the new API Gateway, you do not want the new, you need to annotate the configuration file or use the --skip-event, which makes many users a headache. The new SCF CLI API Gateway in part increased ServiceId fields:
640?wx_fmt=png
With this field, when we used can be selected directly bind the existing gateway. After the new gateway, the system will prompt:
640?wx_fmt=png
The gateway can be avoided next time you create a fill in the corresponding ID. Such a simple field increases, the little fellows brought two excellent experience:
    1: can bind existing API Gateway does not require new
    2: the gateway can ensure that the existing form, not every new

Sixth, to optimize output

It should be noted that small-minded partners, and this update, UI change is very large. When we use cloud functions, different expression will display in different colors:
640?wx_fmt=png
Meanwhile, after Deploy, we do not open the page to see the cloud function information, but directly through the console see:
640?wx_fmt=png

experiment

Hello world

To Hello World, for example, by helping to create the command View init:
scf init --help
640?wx_fmt=png
According to an example of creating Python language hello world:
scf init --runtime python3.6
640?wx_fmt=png
Project editor cd hello_world: Follow the prompts
640?wx_fmt=png
Modify the code and gateway configuration:
640?wx_fmt=png
Gateway to use here, I do not want to create a new gateway, but want to use already have an API Gateway:
640?wx_fmt=png
Fill serviceeId:
640?wx_fmt=png
Then save and exit, Deploy:
640?wx_fmt=png
Once deployed, the output function information:
640?wx_fmt=png
Open API gateway subDomain:
640?wx_fmt=png
Deployment success!

View the list of functions

Just enter scf list
640?wx_fmt=png

Delete function

Only you need to enter the function-related information to be deleted:
scf delete --name hello_world --region ap-shanghai --namespace default
640?wx_fmt=png
This article describes the command-line tools and practices with regard to the appointment of a deputy come to an end.
More features waiting for you to dig their own small partners Oh!

 

Recommended reading:



Published 50 original articles · won praise 4 · Views 2193

Guess you like

Origin blog.csdn.net/weixin_42409476/article/details/101048298
Recommended