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; deployInfo: { ReleaseType: ReleaseTypeEnum }; imageUrl?: 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 |
| deployInfo | Yes | Object | Deployment info, containing:ReleaseType: ReleaseTypeEnum - Release type. Optional values: "GRAY" (canary release), "FULL" (full release) |
| imageUrl | No | String | Image URL. When provided, uses image deployment mode without uploading the code package. |
| 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 | |||
- InstallDependency: boolean - Whether to install dependencies online. If true, node_modules will not be packaged locally | |||
| - OperationMode: string - Operation mode | |||
- SessionAffinity: string - Session affinity. Optional values: "open", "close" | |||
- LogType: string - Log type. Optional values: "none", "default", "custom" | |||
| - LogSetId: string - CLS logset ID | |||
| - LogTopicId: string - CLS topic ID | |||
- LogParseType: string - Log parsing type. Optional values: "json", "line" | |||
| - Tag: string - Service tag | |||
| - TimerScale: ICloudrunTimerScale[] - Scheduled autoscaling configuration | |||
- VpcConf: IVpcConf - VPC network configuration, containing:VpcId: string - VPC IDVpcCIDR: string - VPC CIDR blockSubnetId: string - Subnet IDSubnetCIDR: string - Subnet CIDR block | |||
| - VolumesConf: IVolumeConf[] - Storage mount configuration (COS / CFS) | |||
- PublicNetConf: IPublicNetConf - Public network access configuration, containing:PublicNetStatus: string - Public network status. Optional values: "ENABLE", "DISABLE" |
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",
deployInfo: {
ReleaseType: "FULL",
},
serverConfig: {
Cpu: 0.5,
Mem: 1,
MinNum: 1,
MaxNum: 5,
VpcConf: {
VpcId: "vpc-xxxxxxxx",
SubnetId: "subnet-xxxxxxxx",
},
},
});
console.log("Service deployed successfully");
}
test();
Image deployment example:
async function test() {
await manager.cloudrun.deploy({
serverName: "my-server",
targetPath: "./",
deployInfo: {
ReleaseType: "FULL",
},
imageUrl: "ccr.ccs.tencentyun.com/my-repo/my-image:latest",
});
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();
describeServerManageTask
1. Interface Description
Function: Query a Cloud Hosting service management task. When no task ID is provided, the latest task of the service is returned.
Interface declaration: describeServerManageTask(params: { serverName: string; taskId?: number; operatorRemark?: string }): Promise<{ IsExist?: boolean; Task?: IServerManageTaskInfo; RequestId?: string }>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| serverName | Yes | String | Service name |
| taskId | No | Number | Task ID. Defaults to 0, which queries the latest task of the service |
| operatorRemark | No | String | Operation remark |
3. Response
| Field | Type | Description |
|---|---|---|
| IsExist | Boolean | Whether a matching management task exists |
| Task | IServerManageTaskInfo | Management task information; may be empty when no task exists |
| Task.Id | Number | Task ID |
| Task.EnvId | String | Environment ID |
| Task.ServerName | String | Service name |
| Task.ChangeType | String | Change type |
| Task.ReleaseType | String | Release type |
| Task.DeployType | String | Deployment type |
| Task.PreVersionName | String | Previous version name |
| Task.VersionName | String | Version name associated with the task |
| Task.Status | String | Task status |
| Task.Steps | ITaskStepInfo[] | Step information, including name, status, start and end time, duration, and failure reason |
| Task.FailReason | String | Failure reason |
| Task.OperatorRemark | String | Operation remark |
| RequestId | String | Request ID |
4. Sample Code
const result = await manager.cloudrun.describeServerManageTask({
serverName: "my-server",
});
console.log("Task exists:", result.IsExist);
console.log("Task:", result.Task);
describeVersionDetail
1. Interface Description
Function: Query the detailed configuration and runtime status of a specified Cloud Hosting service version.
Interface declaration: describeVersionDetail(params: { ServerName: string; VersionName: string; Channel?: string }): Promise<IDescribeVersionDetailResponse>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| ServerName | Yes | String | Service name |
| VersionName | Yes | String | Version name |
| Channel | No | String | Channel identifier |
3. Response
| Field | Type | Description |
|---|---|---|
| Name | String | Service name |
| Port | Number | Service port |
| Cpu | Number | CPU specification |
| Mem | Number | Memory specification |
| MinNum | Number | Minimum number of instances |
| MaxNum | Number | Maximum number of instances |
| PolicyDetails | ICloudrunHpaPolicy[] | Autoscaling policies |
| Dockerfile | String | Dockerfile name |
| BuildDir | String | Build directory |
| EnvParams | String | Environment variables |
| Status | String | Version status |
| CreatedTime | String | Creation time |
| UpdatedTime | String | Update time |
| LogPath | String | Log collection path |
| EntryPoint | String | null | Container entry point |
| Cmd | String | null | Container command |
| VpcConf | IVpcConf | null | VPC network configuration |
| VolumesConf | IVolumeConf[] | null | Storage mount configuration |
| BuildPacks | IBuildPacksInfo | null | Build package information, including base image, entry point, language, upload filename, and language version |
| RequestId | String | Request ID |
4. Sample Code
const version = await manager.cloudrun.describeVersionDetail({
ServerName: "my-server",
VersionName: "my-server-0001",
});
console.log("Version status:", version.Status);
console.log("CPU/memory:", version.Cpu, version.Mem);
submitServerRollback
1. Interface Description
Function: Submit a Cloud Hosting version rollback task to roll the current version back to a specified historical version.
Interface declaration: submitServerRollback(params: { ServerName: string; CurrentVersionName: string; RollbackVersionName: string; OperatorRemark?: string }): Promise<ISubmitServerRollbackResponse>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| ServerName | Yes | String | Service name |
| CurrentVersionName | Yes | String | Current version name |
| RollbackVersionName | Yes | String | Target historical version name |
| OperatorRemark | No | String | Operation remark |
3. Response
| Field | Type | Description |
|---|---|---|
| TaskId | Number | Rollback task ID. Use describeServerManageTask to query its status |
| RequestId | String | Request ID |
4. Sample Code
const { TaskId } = await manager.cloudrun.submitServerRollback({
ServerName: "my-server",
CurrentVersionName: "my-server-0002",
RollbackVersionName: "my-server-0001",
OperatorRemark: "rollback-release",
});
console.log("Rollback task submitted:", TaskId);
deleteCloudRunVersions
1. Interface Description
Function: Delete specified Cloud Hosting versions in batches.
Interface declaration: deleteCloudRunVersions(params: IDeleteCloudRunVersionsParams): Promise<IDeleteCloudRunVersionsResponse>
This operation cannot be undone. Version deletion restrictions are validated by the service. Check FailVersions to confirm the result for every requested version.
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| IsDeleteServer | Yes | Boolean | Whether to delete the service. Takes effect only when deleting its last version |
| IsDeleteImage | Yes | Boolean | Whether to delete the image. Takes effect only when deleting the service |
| SimpleVersions | Yes | ISimpleVersion[] | Non-empty list of versions to delete |
| SimpleVersions[].EnvId | No | String | Environment ID. Uses the current environment when omitted |
| SimpleVersions[].ServerName | Yes | String | Service name |
| SimpleVersions[].VersionName | Yes | String | Version name |
| OperatorRemark | No | String | Operation remark |
3. Response
| Field | Type | Description |
|---|---|---|
| Result | String | Overall result: succ, partial, or fail |
| SuccessVersions | ISuccessDeleteVersions[] | Successfully deleted versions |
| SuccessVersions[].Version | ISimpleVersion | Deleted version information |
| SuccessVersions[].RequestId | String | Request ID for deleting the version |
| SuccessVersions[].Result | String | Deletion result |
| FailVersions | IFailDeleteVersions[] | Versions that could not be deleted |
| FailVersions[].Version | ISimpleVersion | Failed version information |
| FailVersions[].ErrorCode | Number | Error code |
| FailVersions[].ErrorMsg | String | Error message |
| FailVersions[].RequestId | String | Request ID for deleting the version |
| RequestId | String | Request ID |
4. Sample Code
const result = await manager.cloudrun.deleteCloudRunVersions({
IsDeleteServer: false,
IsDeleteImage: false,
SimpleVersions: [
{
ServerName: "my-server",
VersionName: "my-server-0001",
},
],
OperatorRemark: "remove-unused-version",
});
console.log("Deletion result:", result.Result);
console.log("Deleted versions:", result.SuccessVersions);
console.log("Failed versions:", result.FailVersions);
getDeployRecords
1. Interface Description
Function: Get Cloud Hosting deployment records, sorted by deployment time in descending order.
Interface declaration: getDeployRecords(params: { serverName: string }): Promise<IDescribeCloudRunDeployRecordResponse>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| serverName | Yes | String | Service name |
3. Response
| Field | Type | Description |
|---|---|---|
| DeployRecords | ICloudRunDeployRecordInfo[] | Deployment record list |
| DeployRecords[].DeployId | String | Deployment ID |
| DeployRecords[].DeployTime | String | Deployment time |
| DeployRecords[].Status | String | Deployment status |
| DeployRecords[].RunId | String | Runtime version ID, used to query runtime logs |
| DeployRecords[].BuildId | Number | Build ID, used to query build logs |
| DeployRecords[].FlowRatio | Number | Traffic ratio, from 0 to 100 |
| DeployRecords[].ImageUrl | String | Image URL |
| DeployRecords[].ScaleStatus | String | Autoscaling status |
| DeployRecords[].HasTraffic | Boolean | Whether the version has traffic |
| DeployRecords[].TrafficType | String | Traffic type |
| DeployRecords[].IsReleasing | Boolean | Whether the version is being released |
| RequestId | String | Request ID |
4. Sample Code
const { DeployRecords } = await manager.cloudrun.getDeployRecords({
serverName: "my-server",
});
console.log("Latest deployment record:", DeployRecords[0]);
getBuildLog
1. Interface Description
Function: Query Cloud Hosting build logs. When buildId is not provided, the SDK queries the latest deployment record and returns its build log.
Interface declaration: getBuildLog(params: { serverName: string; buildId?: number }): Promise<IBuildLogResponse>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| serverName | Yes | String | Service name |
| buildId | No | Number | Build ID. Uses the latest deployment record when omitted |
3. Response
| Field | Type | Description |
|---|---|---|
| Log | IBuildLog | Build log information |
| Log.Total | Number | Total number of log entries |
| Log.Delivered | Number | Number of returned log entries |
| Log.Text | String | Log content |
| Log.More | Boolean | Whether more logs are available |
| Log.FailType | String | Build failure type |
| Log.FailReason | String | Build failure reason |
| RequestId | String | Request ID |
4. Sample Code
const { Log } = await manager.cloudrun.getBuildLog({
serverName: "my-server",
});
console.log(Log.Text);
if (Log.FailReason) {
console.error("Build failure reason:", Log.FailReason);
}
getProcessLog
1. Interface Description
Function: Query Cloud Hosting runtime logs by runtime version ID.
Interface declaration: getProcessLog(params: { RunId: string }): Promise<IProcessLogResponse>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| RunId | Yes | String | Runtime version ID, obtained from getDeployRecords |
3. Response
| Field | Type | Description |
|---|---|---|
| Logs | String[] | Log content array |
| RequestId | String | Request ID |
4. Sample Code
const records = await manager.cloudrun.getDeployRecords({
serverName: "my-server",
});
const runId = records.DeployRecords[0]?.RunId;
if (!runId) {
throw new Error("No deployment record with a runtime version was found");
}
const { Logs } = await manager.cloudrun.getProcessLog({ RunId: runId });
console.log(Logs.join("\n"));