Skip to main content

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

FieldRequiredTypeDescription
serverNameYesStringService name, which will be used as the project directory name
templateNoStringTemplate identifier, defaults to 'helloworld'
targetPathNoStringTarget path, defaults to the current directory

3. Response

FieldTypeDescription
projectDirStringInitialized 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

FieldRequiredTypeDescription
serverNameYesStringService name to download
targetPathYesStringTarget 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

FieldRequiredTypeDescription
pageSizeNoNumberNumber of items per page, default 10
pageNumNoNumberPage number, default 1
serverNameNoStringService name filter
serverTypeNoCloudrunServerTypeService type filter (function/container)

3. Response

FieldTypeDescription
ServerListICloudrunServerBaseInfo[]Service list array
ServerList[].ServerNameStringService name
ServerList[].DefaultDomainNameStringDefault service domain
ServerList[].CustomDomainNameStringCustom domain name
ServerList[].StatusStringService status (running/deploying/deploy_failed)
ServerList[].UpdateTimeStringUpdate time
ServerList[].AccessTypesString[]Public network access types array
ServerList[].CustomDomainNamesString[]Custom domain names array
ServerList[].ServerTypeStringService type (function/container)
ServerList[].TrafficTypeStringTraffic type
TotalNumberTotal services
RequestIdStringRequest 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

FieldRequiredTypeDescription
serverNameYesStringService name to query

3. Response

FieldTypeDescription
BaseInfoICloudrunServerBaseInfoBasic service information
BaseInfo.ServerNameStringService name
BaseInfo.DefaultDomainNameStringDefault service domain
BaseInfo.CustomDomainNameStringCustom domain name
BaseInfo.StatusStringService status
BaseInfo.UpdateTimeStringUpdate time
BaseInfo.AccessTypesString[]Public network access types
BaseInfo.CustomDomainNamesString[]Custom domain names
BaseInfo.ServerTypeStringService type
BaseInfo.TrafficTypeStringTraffic type
ServerConfigICloudrunServerBaseConfigService configuration information
ServerConfig.EnvIdStringEnvironment ID
ServerConfig.ServerNameStringService name
ServerConfig.OpenAccessTypesString[]Public network access types
ServerConfig.CpuNumberCPU spec
ServerConfig.MemNumberMemory spec
ServerConfig.MinNumNumberMinimum replica count
ServerConfig.MaxNumNumberMaximum replica count
ServerConfig.PolicyDetailsICloudrunHpaPolicy[]Autoscaling configuration
ServerConfig.PolicyDetails[].PolicyTypeStringAutoscaling 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[].PolicyThresholdNumberAutoscaling threshold (percentage). Value range: 0-100. For example, 60 means autoscaling is triggered when resource utilization reaches 60%.
ServerConfig.CustomLogsStringLog collection path
ServerConfig.EnvParamsStringEnvironment variable
ServerConfig.InitialDelaySecondsNumberInitial delay
ServerConfig.CreateTimeStringCreation time
ServerConfig.PortNumberService port
ServerConfig.HasDockerfileBooleanWhether a Dockerfile exists
ServerConfig.DockerfileStringDockerfile name
ServerConfig.BuildDirStringBuild directory
ServerConfig.LogTypeStringLog type
ServerConfig.LogSetIdStringCLS logset ID
ServerConfig.LogTopicIdStringCLS topic ID
ServerConfig.LogParseTypeStringLog parsing type
ServerConfig.TagStringService tag
ServerConfig.InternalAccessStringIntranet access switch
ServerConfig.InternalDomainStringIntranet domain
ServerConfig.OperationModeStringOperation mode
ServerConfig.TimerScaleICloudrunTimerScale[]Scheduled autoscaling configuration
ServerConfig.TimerScale[].CycleTypeStringCycle type, optional values:
- "none": No cycle
- "daily": Daily cycle
- "weekly": Weekly cycle
- "monthly": Monthly cycle
ServerConfig.TimerScale[].StartDateStringCycle start date (Format: YYYY-MM-DD)
ServerConfig.TimerScale[].EndDateStringCycle end date (Format: YYYY-MM-DD)
ServerConfig.TimerScale[].StartTimeStringStart time (Format: HH:mm:ss)
ServerConfig.TimerScale[].EndTimeStringEnd time (Format: HH:mm:ss)
ServerConfig.TimerScale[].ReplicaNumNumberReplica count (min: 0)
ServerConfig.EntryPointString[]Dockerfile EntryPoint parameters
ServerConfig.CmdString[]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

FieldRequiredTypeDescription
serverNameYesStringService name to delete

3. Response

FieldTypeDescription
RequestIdStringRequest 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

FieldRequiredTypeDescription
serverNameYesStringService name to be deployed
targetPathYesStringLocal code path
deployInfoYesObjectDeployment info, containing:
ReleaseType: ReleaseTypeEnum - Release type. Optional values: "GRAY" (canary release), "FULL" (full release)
imageUrlNoStringImage URL. When provided, uses image deployment mode without uploading the code package.
serverConfigNoPartial<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 ID
VpcCIDR: string - VPC CIDR block
SubnetId: string - Subnet ID
SubnetCIDR: 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

FieldTypeDescription
RequestIdStringRequest 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

FieldTypeDescription
ITemplate[]ArrayTemplate array
[].identifierStringTemplate unique identifier
[].titleStringTemplate title
[].descriptionStringTemplate description
[].runtimeVersionStringRuntime version
[].languageStringProgramming language
[].zipFileStoreStringTemplate 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

FieldRequiredTypeDescription
serverNameYesStringService name
taskIdNoNumberTask ID. Defaults to 0, which queries the latest task of the service
operatorRemarkNoStringOperation remark

3. Response

FieldTypeDescription
IsExistBooleanWhether a matching management task exists
TaskIServerManageTaskInfoManagement task information; may be empty when no task exists
Task.IdNumberTask ID
Task.EnvIdStringEnvironment ID
Task.ServerNameStringService name
Task.ChangeTypeStringChange type
Task.ReleaseTypeStringRelease type
Task.DeployTypeStringDeployment type
Task.PreVersionNameStringPrevious version name
Task.VersionNameStringVersion name associated with the task
Task.StatusStringTask status
Task.StepsITaskStepInfo[]Step information, including name, status, start and end time, duration, and failure reason
Task.FailReasonStringFailure reason
Task.OperatorRemarkStringOperation remark
RequestIdStringRequest 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

FieldRequiredTypeDescription
ServerNameYesStringService name
VersionNameYesStringVersion name
ChannelNoStringChannel identifier

3. Response

FieldTypeDescription
NameStringService name
PortNumberService port
CpuNumberCPU specification
MemNumberMemory specification
MinNumNumberMinimum number of instances
MaxNumNumberMaximum number of instances
PolicyDetailsICloudrunHpaPolicy[]Autoscaling policies
DockerfileStringDockerfile name
BuildDirStringBuild directory
EnvParamsStringEnvironment variables
StatusStringVersion status
CreatedTimeStringCreation time
UpdatedTimeStringUpdate time
LogPathStringLog collection path
EntryPointString | nullContainer entry point
CmdString | nullContainer command
VpcConfIVpcConf | nullVPC network configuration
VolumesConfIVolumeConf[] | nullStorage mount configuration
BuildPacksIBuildPacksInfo | nullBuild package information, including base image, entry point, language, upload filename, and language version
RequestIdStringRequest 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

FieldRequiredTypeDescription
ServerNameYesStringService name
CurrentVersionNameYesStringCurrent version name
RollbackVersionNameYesStringTarget historical version name
OperatorRemarkNoStringOperation remark

3. Response

FieldTypeDescription
TaskIdNumberRollback task ID. Use describeServerManageTask to query its status
RequestIdStringRequest 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>

Notice

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

FieldRequiredTypeDescription
IsDeleteServerYesBooleanWhether to delete the service. Takes effect only when deleting its last version
IsDeleteImageYesBooleanWhether to delete the image. Takes effect only when deleting the service
SimpleVersionsYesISimpleVersion[]Non-empty list of versions to delete
SimpleVersions[].EnvIdNoStringEnvironment ID. Uses the current environment when omitted
SimpleVersions[].ServerNameYesStringService name
SimpleVersions[].VersionNameYesStringVersion name
OperatorRemarkNoStringOperation remark

3. Response

FieldTypeDescription
ResultStringOverall result: succ, partial, or fail
SuccessVersionsISuccessDeleteVersions[]Successfully deleted versions
SuccessVersions[].VersionISimpleVersionDeleted version information
SuccessVersions[].RequestIdStringRequest ID for deleting the version
SuccessVersions[].ResultStringDeletion result
FailVersionsIFailDeleteVersions[]Versions that could not be deleted
FailVersions[].VersionISimpleVersionFailed version information
FailVersions[].ErrorCodeNumberError code
FailVersions[].ErrorMsgStringError message
FailVersions[].RequestIdStringRequest ID for deleting the version
RequestIdStringRequest 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

FieldRequiredTypeDescription
serverNameYesStringService name

3. Response

FieldTypeDescription
DeployRecordsICloudRunDeployRecordInfo[]Deployment record list
DeployRecords[].DeployIdStringDeployment ID
DeployRecords[].DeployTimeStringDeployment time
DeployRecords[].StatusStringDeployment status
DeployRecords[].RunIdStringRuntime version ID, used to query runtime logs
DeployRecords[].BuildIdNumberBuild ID, used to query build logs
DeployRecords[].FlowRatioNumberTraffic ratio, from 0 to 100
DeployRecords[].ImageUrlStringImage URL
DeployRecords[].ScaleStatusStringAutoscaling status
DeployRecords[].HasTrafficBooleanWhether the version has traffic
DeployRecords[].TrafficTypeStringTraffic type
DeployRecords[].IsReleasingBooleanWhether the version is being released
RequestIdStringRequest 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

FieldRequiredTypeDescription
serverNameYesStringService name
buildIdNoNumberBuild ID. Uses the latest deployment record when omitted

3. Response

FieldTypeDescription
LogIBuildLogBuild log information
Log.TotalNumberTotal number of log entries
Log.DeliveredNumberNumber of returned log entries
Log.TextStringLog content
Log.MoreBooleanWhether more logs are available
Log.FailTypeStringBuild failure type
Log.FailReasonStringBuild failure reason
RequestIdStringRequest 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

FieldRequiredTypeDescription
RunIdYesStringRuntime version ID, obtained from getDeployRecords

3. Response

FieldTypeDescription
LogsString[]Log content array
RequestIdStringRequest 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"));