Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Cloud Development Cloud Development Resource Management


May 22, 2021 Mini Program Cloud Development Advanced



First, the developer's tool chain

1, through the cloud development web background management cloud development resources

We can log on to Tencent Cloud's official website for cloud development background management, choose to use WeChat public number login, and then use the small program administrator's WeChat to scan QR code, you can see in the web console we use WeChat developer tools to create a small program cloud development resources.

Cloud Development Cloud Development Resource Management

Here you can manage databases, files (storage), cloud functions, monitoring alerts, log retrieval, and environment settings for small program cloud development, or you can renew the services of cloud development resources, which is a visual management tool that can completely replace the cloud development console.

Cloud Development Cloud Development Resource Management

Tencent Cloud's cloud development web console is more comprehensive than the developer's console, and many new features will be released here first, such as:

  • Static site hosting: you can hexo, vuepress, hugo and other generated static blogs, self-created static web site hosting to the cloud development environment;

  • Cache settings for file storage: Cache expiration configuration is a set of caching policies for user files, which can reduce the CDN back-source rate;

  • Cloud storage security rules:

  • User-managed login settings: cross-multi-end essential functions to support custom login, WeChat public platform, WeChat open platform and anonymous login;

  • HTTP trigger for cloud functions: HTTP trigger is an HTTP access service provided by cloud development for developers, allowing developers to access their own cloud development resources through HTTP.

  • Private network is a piece of logical isolation network space customized on Tencent cloud, which can build logical isolation and user-defined network space for cloud servers, cloud databases and other resources, in order to improve the security of resources on the user cloud and meet the needs of different application scenarios.

  • Cloud functions support php in addition to Nodejs, which may later add more programming languages;

  • You can buy resources from the cloud environment by resource pack, and after you turn on pay-as-you-go, it's more cost-effective to buy a resource pack;

  • Automatic degradation of the cloud development environment: If the conditions are met after the expiration of the cloud development environment, the system will automatically reduce you to a free version of the environment, to avoid the storage of resources due to the payment is not timely and empty

  • Expansion capabilities: Support image security audit, image labeling, image processing, image blind watermarking, etc., and expansion capabilities continue to be added

2, cross-cloud development environment management

If you have multiple cloud development environments (small program cloud development environment, web cloud development environment, etc.), and you have multiple cloud development resource environments, can we call the cloud development resources of B small programs in the cloud function of A small programs? Of course, you can @cloudbase implementation by using the dependency /node-sdk.

@cloudbase/node-sdk is the service-side SDK for cloud development, allowing you to access cloud-developed services using Nodejs services on the service side (such as Tencent cloud functions or CVMs, etc.), which means that service-side SDK is a necessary dependency for cloud development environments. The dependency was installed at the same time when we installed wx-server-sdk for the cloud function, which means that we can use it directly to implement a cross-cloud development environment to invoke resources without having to install it again.

For example, we can fill in the cloud functions of the A small program the secretId and the secretKey of the B small program and the environment ID, here the secretId and the secretKey,

  • You can fill in the B small program appid and key, this can be found in the B small program console, because the small program cloud development environment can create two, so we can fill in the environment ID to determine which environment;

  • You can also Tencent Cloud API fixed key pair, Tencent cloud key pair acquisition, this key pair will manage all the cloud development environment under the account, we can fill in the environment ID to really which environment

  • If you don't fill in the secretId and secretKey, it means that the initialization is the cloud development environment for the A-program.

For example, we would like to add and edit the database of the B small program in the cloud function of the A small program, such as the cloud function named cross in the cloud function of the A small program, write the following code in the index.js of the cros cloud function, when we call the cross cloud function in the small program, we can add a record to the database of the B small program:

  1. const cloud = require('wx-server-sdk')
  2. cloud.init({ //任意云开发环境,包含B小程序创建的云开发环境,你一定要找到对应的腾讯云的secretId和secretKey哦
  3. secretId: 'AKIDUmqiIcQUyA...GsDH6frnvcjZ',
  4. secretKey: 'iChEVXL7mBKJ...GqRmrgFYZ7',
  5. env: 'hac...1279b'
  6. })
  7. const db = cloud.database()
  8. exports.main = async (event, context) => {
  9. const {OPENID} = cloud.getWXContext()
  10. const result = await db.collection('test').add({
  11. data:{
  12. openid:OPENID,
  13. name:"李东bbsky",
  14. interest:['爬山','旅游','读书']
  15. }
  16. })
  17. return result
  18. }

The service-side SDK, @cloudbase/node-sdk, is consistent with the use of the small program cloud function side (service-side). More information about this dependency can be found by reading the technical documentation on Github.

@cloudbase/node-sdk is the service-side SDK of cloud development nodejs, while cloud development is also supporting more programming languages such as php, while tcb-php-sdk is the service-side SDK of cloud development php language.

3, through the CLI tool to manage cloud development resources

CloudBase CLI is an open source command-line interface interaction tool that helps users quickly and easily deploy projects and manage cloud development resources. For developers, we can also use the cloudbase-cli CLI tool to manage cloud development resources using the command line.

If you want to use Visual Studio Code to develop small programs and web-side cloud development on-premises, you can use cloudbase Cli command-line tools to manage the environment for cloud development.

  • The creation of the cloud development environment, the creation of the environment configuration, change the way the environment logs on, display the environment information;

  • Cloud function list display, download, deployment, delete, update code, update configuration, copy cloud function, print cloud function log, trigger cloud function;

  • File storage file list, file temporary access address, file information, file permission acquisition and settings, file/folder upload, delete, list acquisition, information acquisition;

  • Deployment and deletion of static sites

  • HTTP Service creation, deletion, binding, untie, query, etc

Deploying Nodejs environments on-premises on-premises, combined with the VS Code editor, Cloudbase CLI is an important tool that can replace WeChat developer tools for cross-end cloud development, although some of the applets and web pages are account-related debugging or can not be separated from WeChat developer tools.

Second, cloud development background management system development

How should we let the market, operations, products, etc. to manage cloud development resources (such as adding goods, publishing articles, etc.), usually we need to build a background, easy to understand the code of people to visual management, although we can put this background directly in the small program, but the PC side of the background may be more convenient.

1、cloudbase-manager-node

Cloudbase-manager-node is the management side SDK of cloud development, which supports developers to create, manage, configure, and so on the cloud functions, databases, file storage and other resources provided by cloud development through interfaces.

Compared to the service-side SDK developed by the cloud, the management-side SDK is more powerful in managing the resources of the cloud development environment, and the management-side SDK can be used to build the management background of the cloud development environment on-premises pc, Linux, Windows and other servers. We can still introduce the management side sdk cloudbase-manager-node to the cloud function and get some capabilities that the service side sdk (wx-server-sdk) does not have, such as:

  • Check the existence of the collection and delete the collection, check the existence of the collection through the checkCollectionExists ('') interface, use it in combination with the creation of the collection, can be said to be the combination of heaven;

  • Operation index, update index, determine whether index exists, get index information, index hits, size;

  • Import and export data, import csv or json files from the object store into the database, or export the data from the database to csv or json files, and get whether the import export is successful or not;

  • Folder operation, upload or delete folder, get information about all files in the folder, get and cloud storage permissions;

  • Operate cloud functions, get a list of cloud functions, create and delete cloud functions, update the code and configuration of cloud functions, create and remove triggers for cloud functions;

  • Create a publishing layer Layer, through Layer, the same account within the cloud function can be re-used code blocks, cross-account can share code blocks;

  • Operating security rules, not only can you view the security rules of database and cloud storage, but also modify the security rules of database and cloud storage.

tcb-php-sdk is the service-side SDK of the php language developed by the cloud, and correspondingly, tcb-manager-php is the management side SDK of the php language developed by the cloud.

2, web side SDK

Cloud development is also applicable to website development, the web side is the general name for website applications in cloud development, including the following scenarios: ordinary website applications (PC side), mobile pages or H5 pages, public pages. I f you want to cloud development this server-free development concept and way to the web side, you can also directly switch the environment of small program cloud development to pay-per-view, then this environment can become a web-side development environment, the realization of a cloud-based, without the need for additional servers to manage the resources in the web web side of the small program cloud development environment. Later, we'll also briefly cover Web cloud development.

3, cloud access (HTTP trigger)

Cloud access is an HTTP access service for developers based on cloud functions, and developers can easily access all resources within the cloud development environment through HTTP requests using POST, PUT, GET, DELETE, etc., without the need for a Web-side SDK, as described later.

4, the use of HTTP API to manage cloud development resources

Developers can also use the HTTP API to set up a web background, which works in all programming languages and all platforms. T he official technical documentation for cloud development has very detailed HTTP API technical documentation, through the HTTP API we can implement the collection of databases, records, files, etc. to add and edit and trigger cloud functions. HTTP APIs can be completely replaced by cloud access and SDKs, so we're not going to go into http://www.s