Skip to main content

Quick Start

Preparations

  1. Install the CLI tool
  2. Log in to the CLI tool

Initialize Directory

mkdir my-cloudbase-service && cd my-cloudbase-service
mkdir functions && mkdir functions/hello
touch cloudbaserc.json functions/hello/index.js

Then we have a directory with the following structure:

.
├── cloudbaserc.json
└── functions
└── hello
└── index.js

In cloudbaserc.json`, fill in the environment ID:

// cloudbaserc.json
{
"envId": "your-env-id"
}

In functions/hello/index.js`, write a simple Hello World:

// functions/hello/index.js
exports.main = async function () {
return "Hello World!";
};

Deploy Cloud Function

Execute the following command:

cloudbase fn deploy hello

After waiting, the cloud function is successfully deployed:

cloudbase fn deploy hello
? No function publish configuration found, use the default configuration? Yes
✔ [hello] Function deployed successfully!

Create HTTP Route for Cloud Function

Execute the following command to create an HTTP route with the path /hello pointing to the cloud function hello:

cloudbase service create -p hello -f hello

Note: The CLI version must be 1.0.6 or above.

Accessing Cloud Functions via HTTP

The function can then be accessed directly via https://${env}.service.tcloudbase.com/hello, where ${env} is the environment ID.

curl https://${env}.service.tcloudbase.com/hello
hello world!

You can also open https://${env}.service.tcloudbase.com/hello directly in your browser.