Skip to main content

Quick Start

This quickstart will guide you through deploying a Vue Website using CloudBase CLI.

0. Activate Cloud Development Service

If you already have a pay-as-you-go Cloud Development environment, you can skip this step.

Before using the Cloud Development service, you need to log in to the Tencent Cloud Cloud Development Console to ensure that the Cloud Development service has been activated and a usable environment has been created. If you are unfamiliar with environment creation, please follow the Cloud Development Quick Start - Activating Environment documentation.

1. Sign In

First, log in to your Tencent Cloud account. After obtaining your authorization, CloudBase CLI can operate your resources. CloudBase CLI provides two methods to obtain authorization: Tencent Cloud - Cloud Development Console authorization and Tencent Cloud - Cloud API key authorization.

tip

For international users, before logging in, you need to execute the command tcb config set isIntl true to switch the request route to the international site, and then proceed to log in.

Alternatively, you can switch by setting the environment variable TCB_IS_INTL=true.

Tencent Cloud - Cloud Development Console Authorization

Enter the following command in your terminal:

tcb login

Scaling out clusters is a common method of resource configuration. Ops personnel can dynamically adjust the node scale in real time via the Tencent Cloud console or APIs.

tip

If your account is not a primary account, please refer to the Sub-account Login section in the login instructions.

Tencent Cloud - Cloud API Key Authorization

tip

Tencent Cloud API keys can access all resources under your account. Please securely store and regularly rotate your keys. When replacing keys, promptly delete the old ones.

First, you need to go to the Tencent Cloud official website to obtain the Cloud API Key, then enter the following command in your terminal:

tcb login --key

Press Enter, then enter the SecretId and SecretKey of your Cloud API Key as prompted to complete the login.

Login in CI

In CI (Continuous Integration) builds, you can use the following method to log in directly via API keys, avoiding interactive input:

tcb login --apiKeyId xxx --apiKey xxx

2. Create a Project

Initialization

You can use the following command to create a project. When creating a project, CloudBase CLI will create a folder based on the project name you entered and write relevant configuration and template files.

tip

Using the tcb new command requires CLI version 1.0+.

tcb new app node-starter

Cloud Development projects are entities associated with Cloud Development environment resources. A Cloud Development project aggregates services such as Cloud Functions, databases, and file storage. Within a Cloud Development project, you can write functions, store files, and efficiently manage your cloud functions, file storage, databases, and other resources through CloudBase.

Cloud Development project file structure:

.
├── .gitignore
├── functions // cloud functions directory
│   └── node-app
│   └── index.js
└── cloudbaserc.json // project configuration file

Write functions

By default, all Node and PHP functions are stored in the functions directory, with each function's name as the folder name, such as functions/node-app/index.js. For Java functions, you need to rename the jar file to match the function name and place it directly under the functions directory, for example, functions/cloudbase.jar. If you wish to store functions in a different directory, you can specify the desired directory using the functionRoot option in the configuration file. The functionRoot option represents the path of the cloud functions folder relative to the project root directory.

For example, to create a Node.js function app, below is the content of functions/app/index.js

"use strict";

exports.main = async (event, context) => {
console.log("Hello World");
console.log(event);
console.log(context);
};

Update configuration

By default, project configuration is stored in the cloudbaserc.json file. The default generated function configuration is for Node.js. For other languages such as PHP and Java, you need to modify the corresponding handler (entry point) and runtime (runtime environment). Refer to the configuration file documentation for details on the cloudbaserc.json file.

If you wish to specify another file as the configuration file, you can add the --config-file config-path parameter when using CLI commands to designate the configuration file. Currently, configuration files in JS and JSON formats are supported.

{
"envId": "xxx",
"functionRoot": "./functions",
"functions": [
{
"name": "node-app",
"timeout": 5,
"envVariables": {},
"runtime": "Nodejs10.15",
"memorySize": 128,
"handler": "index.main"
}
]
}

3. Deploy Functions

Run the command tcb fn deploy node-app in the project root directory (where the cloudbaserc.json file is located) to deploy the node-app function.

tcb fn deploy node-app

After deployment, you can use the tcb fn list command to view the list of deployed functions.

tcb fn list