Cloud Hosting
init
1. Interface Description
Function: Initialize the Cloud Hosting code project.
Interface declaration: init(params: { serverName: string; template?: string; targetPath?: string }): Promise<{ projectDir: string }>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| serverName | Yes | String | Service name, which will be used as the project directory name |
| template | No | String | Template identifier, defaults to 'helloworld' |
| targetPath | No | String | Target path, defaults to the current directory |
3. Response
| Field | Type | Description |
|---|---|---|
| projectDir | String | Initialized project directory |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const { projectDir } = await manager.cloudrun.init({
serverName: "my-server",
template: "helloworld",
targetPath: "./projects",
});
console.log("Project has been initialized to:", projectDir);
}
test();
download
1. Interface Description
Function: Download the Cloud Hosting service code to the local directory.
Interface declaration: download(params: { serverName: string; targetPath: string }): Promise<void>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| serverName | Yes | String | Service name to download |
| targetPath | Yes | String | Target path for download (absolute or relative path) |
3. Response
No direct data is returned. The Promise resolves on success and rejects on failure.
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await manager.cloudrun.download({
serverName: "my-server",
targetPath: "./downloads",
});
console.log("Code download completed");
}
test();
list
1. Interface Description
Function: Get the list of Cloud Hosting services
Interface declaration: list(params?: { pageSize?: number; pageNum?: number; serverName?: string; serverType?: CloudrunServerType }): Promise<ICloudrunListResponse>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| pageSize | No | Number | Number of items per page, default 10 |
| pageNum | No | Number | Page number, default 1 |
| serverName | No | String | Service name filter |
| serverType | No | CloudrunServerType | Service type filter (function/container) |
3. Response
| Field | Type | Description |
|---|---|---|
| ServerList | ICloudrunServerBaseInfo[] | Service list array |
| ServerList[].ServerName | String | Service name |
| ServerList[].DefaultDomainName | String | Default service domain |
| ServerList[].CustomDomainName | String | Custom domain name |
| ServerList[].Status | String | Service status (running/deploying/deploy_failed) |
| ServerList[].UpdateTime | String | Update time |
| ServerList[].AccessTypes | String[] | Public network access types array |
| ServerList[].CustomDomainNames | String[] | Custom domain names array |
| ServerList[].ServerType | String | Service type (function/container) |
| ServerList[].TrafficType | String | Traffic type |
| Total | Number | Total services |
| RequestId | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const { ServerList, Total } = await manager.cloudrun.list({
pageSize: 20,
pageNum: 1,
});
console.log(`Total ${Total} services:`, ServerList);
}
test();
detail
1. Interface Description
Function: Query the details of the Cloud Hosting service
Interface declaration: detail(params: { serverName: string }): Promise<ICloudrunDetailResponse>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| serverName | Yes | String | Service name to query |
3. Response
| Field | Type | Description |
|---|---|---|
| BaseInfo | ICloudrunServerBaseInfo | Basic service information |
| BaseInfo.ServerName | String | Service name |
| BaseInfo.DefaultDomainName | String | Default service domain |
| BaseInfo.CustomDomainName | String | Custom domain name |
| BaseInfo.Status | String | Service status |
| BaseInfo.UpdateTime | String | Update time |
| BaseInfo.AccessTypes | String[] | Public network access types |
| BaseInfo.CustomDomainNames | String[] | Custom domain names |
| BaseInfo.ServerType | String | Service type |
| BaseInfo.TrafficType | String | Traffic type |
| ServerConfig | ICloudrunServerBaseConfig | Service configuration information |
| ServerConfig.EnvId | String | Environment ID |
| ServerConfig.ServerName | String | Service name |
| ServerConfig.OpenAccessTypes | String[] | Public network access types |
| ServerConfig.Cpu | Number | CPU spec |
| ServerConfig.Mem | Number | Memory spec |
| ServerConfig.MinNum | Number | Minimum replica count |
| ServerConfig.MaxNum | Number | Maximum replica count |
| ServerConfig.PolicyDetails | ICloudrunHpaPolicy[] | Autoscaling configuration |
| ServerConfig.PolicyDetails[].PolicyType | String | Autoscaling type. Valid values: - "cpu": Autoscaling based on CPU utilization- "mem": Autoscaling based on memory utilization- "cpu/mem": Autoscaling based on both CPU and memory utilization |
| ServerConfig.PolicyDetails[].PolicyThreshold | Number | Autoscaling threshold (percentage). Value range: 0-100. For example, 60 means autoscaling is triggered when resource utilization reaches 60%. |
| ServerConfig.CustomLogs | String | Log collection path |
| ServerConfig.EnvParams | String | Environment variable |
| ServerConfig.InitialDelaySeconds | Number | Initial delay |
| ServerConfig.CreateTime | String | Creation time |
| ServerConfig.Port | Number | Service port |
| ServerConfig.HasDockerfile | Boolean | Whether a Dockerfile exists |
| ServerConfig.Dockerfile | String | Dockerfile name |
| ServerConfig.BuildDir | String | Build directory |
| ServerConfig.LogType | String | Log type |
| ServerConfig.LogSetId | String | CLS logset ID |
| ServerConfig.LogTopicId | String | CLS topic ID |
| ServerConfig.LogParseType | String | Log parsing type |
| ServerConfig.Tag | String | Service tag |
| ServerConfig.InternalAccess | String | Intranet access switch |
| ServerConfig.InternalDomain | String | Intranet domain |
| ServerConfig.OperationMode | String | Operation mode |
| ServerConfig.TimerScale | ICloudrunTimerScale[] | Scheduled autoscaling configuration |
| ServerConfig.TimerScale[].CycleType | String | Cycle type, optional values: - "none": No cycle- "daily": Daily cycle- "weekly": Weekly cycle- "monthly": Monthly cycle |
| ServerConfig.TimerScale[].StartDate | String | Cycle start date (Format: YYYY-MM-DD) |
| ServerConfig.TimerScale[].EndDate | String | Cycle end date (Format: YYYY-MM-DD) |
| ServerConfig.TimerScale[].StartTime | String | Start time (Format: HH:mm:ss) |
| ServerConfig.TimerScale[].EndTime | String | End time (Format: HH:mm:ss) |
| ServerConfig.TimerScale[].ReplicaNum | Number | Replica count (min: 0) |
| ServerConfig.EntryPoint | String[] | Dockerfile EntryPoint parameters |
| ServerConfig.Cmd | String[] | Dockerfile Cmd arguments |
| OnlineVersionInfos | ICloudrunOnlineVersionInfo[] | Online version information |
| OnlineVersionInfos[].VersionName | String | Version name |
| OnlineVersionInfos[].ImageUrl | String | Image URL |
| OnlineVersionInfos[].FlowRatio | String | Traffic ratio |
| RequestId | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const detail = await manager.cloudrun.detail({
serverName: "my-server",
});
console.log("Service details:", detail);
}
test();
delete
1. Interface Description
Function: Delete the specified cloud hosting service
Interface declaration: delete(params: { serverName: string }): Promise<IResponseInfo>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| serverName | Yes | String | Service name to delete |
3. Response
| Field | Type | Description |
|---|---|---|
| RequestId | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await manager.cloudrun.delete({
serverName: "my-server",
});
console.log("Service deleted successfully");
}
test();
deploy
1. Interface Description
Function: Deploy local code to the cloud hosting service.
Interface declaration: deploy(params: { serverName: string; targetPath: string; serverConfig?: Partial<ICloudrunServerBaseConfig> }): Promise<IResponseInfo>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| serverName | Yes | String | Service name to be deployed |
| targetPath | Yes | String | Local code path |
| serverConfig | No | Partial<ICloudrunServerBaseConfig> | Service configuration item, including the following optional fields: |
- OpenAccessTypes: string[] - Public network access types. Optional values:"OA" - Office network access"PUBLIC" - Public network access"MINIAPP" - Mini Program access"VPC" - VPC access | |||
| - Cpu: number - CPU spec | |||
| - Mem: number - Memory spec | |||
| - MinNum: number - Minimum number of instances | |||
| - MaxNum: number - Maximum number of instances | |||
- PolicyDetails: ICloudrunHpaPolicy[] - Array of autoscaling configurations. Each element contains:PolicyType: string - Autoscaling type. Optional values: "cpu", "mem", "cpu/mem"PolicyThreshold: number - Autoscaling threshold (percentage), e.g., 60 indicates 60% | |||
| - CustomLogs: string - Custom log configuration | |||
| - EnvParams: string - Environment variable JSON string | |||
| - Port: number - Service port (fixed to 3000 for function-type services) | |||
| - Dockerfile: string - Dockerfile name | |||
| - BuildDir: string - Build directory | |||
| - InternalAccess: string - Intranet access switch | |||
| - InternalDomain: string - Intranet domain | |||
| - EntryPoint: string[] - Dockerfile EntryPoint parameters | |||
| - Cmd: string[] - Dockerfile Cmd arguments |
3. Response
| Field | Type | Description |
|---|---|---|
| RequestId | String | Request ID |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
await manager.cloudrun.deploy({
serverName: "my-server",
targetPath: "./my-project",
serverConfig: {
Cpu: 0.5,
Mem: 1,
MinNum: 1,
MaxNum: 5,
},
});
console.log("Service deployed successfully");
}
test();
getTemplates
1. Interface Description
Function: Get the list of Cloud Hosting service templates
Interface declaration: getTemplates(): Promise<ITemplate[]>
2. Input Parameters
None
3. Response
| Field | Type | Description |
|---|---|---|
| ITemplate[] | Array | Template array |
| [].identifier | String | Template unique identifier |
| [].title | String | Template title |
| [].description | String | Template description |
| [].runtimeVersion | String | Runtime version |
| [].language | String | Programming language |
| [].zipFileStore | String | Template zip file storage location |
4. Sample Code
import CloudBase from "@cloudbase/manager-node";
const manager = new CloudBase({
secretId: "Your SecretId",
secretKey: "Your SecretKey",
envId: "Your envId",
});
async function test() {
const templates = await manager.cloudrun.getTemplates();
console.log("Available templates:", templates);
templates.forEach((template) => {
console.log(`Template ID: ${template.identifier}`);
console.log(`Title: ${template.title}`);
console.log(`Description: ${template.description}`);
console.log(`Runtime version: ${template.runtimeVersion}`);
console.log(`Language: ${template.language}`);
console.log(`Download URL: ${template.zipFileStore}`);
});
}
test();