Enable and Create Your First Environment
This document is intended for platform integrators and introduces how to enable the CloudBase service through Tencent Cloud APIs and create your first environment, as the foundation for allocating environments to tenants later.
Prerequisites
Before creating an environment, confirm the account status and available resources through the following APIs:
- Check whether the CloudBase service is enabled: CheckTcbService
- Query the environment count limit: DescribeEnvLimit
- Get the list of available regions: DescribeTcbRegions
- Get the list of available packages: DescribeBaasPackageList
Before creating your first environment, you need to enable the CloudBase service, including agreeing to the terms of service, authorizing service role permissions, and other initialization operations. After that, you can continue to create environments.
Call CreateEnv to Create an Environment
Call the CreateEnv API to create an environment. The API automatically places an order and deducts the payment. Key parameters:
| Parameter | Description |
|---|---|
PackageId | Package ID; see the common packages table below; can be obtained via DescribeBaasPackageList |
Alias | Environment alias. Only lowercase letters, digits and hyphens (-) are supported; cannot start or end with -, cannot contain two consecutive -, and the length cannot exceed 20 characters |
Resources | Resource types needed in the environment; see the table below |
Period | Purchase duration (months), range 1-12 or 24, default 1 |
RenewFlag | Auto-renewal flag: NOTIFY_AND_AUTO_RENEW (notify and auto-renew) / NOTIFY_AND_MANUAL_RENEW (notify without auto-renewal, default) |
Tags | Environment tags, used for permission isolation and resource grouping; it is recommended to tag by tenant ID and business line |
EnableOverrun | Overrun pay-as-you-go switch, values TRUE / FALSE; it is recommended to set it to TRUE, otherwise the service will be suspended when the package usage is exhausted |
ExternalStorage | Shared COS bucket configuration. Used when the number of environments under a single account exceeds 150 and the COS bucket quota is reached; see Appendix: Shared COS Bucket |
Common package IDs:
| Package ID | Package name | Applicable scenario |
|---|---|---|
baas_integration | Integration | Platform-type customers that need to create a large number of environments under one account |
baas_personal | Personal | Getting started trial, personal development |
baas_pf_standard | Standard | Small teams, production environments |
baas_pf_enterprise | Enterprise | Enterprise-level business |
Resources values:
| Value | Description |
|---|---|
postgresql | PostgreSQL database (relational database, supports SQL) |
storage | Object storage (cloud storage) |
function | Cloud Function (including HTTP cloud functions) |
The following is a Node.js SDK example (it is recommended to inject credentials through environment variables to avoid hardcoding):
const tencentcloud = require("tencentcloud-sdk-nodejs");
const TcbClient = tencentcloud.tcb.v20180608.Client;
const client = new TcbClient({
credential: {
secretId: process.env.TENCENTCLOUD_SECRETID,
secretKey: process.env.TENCENTCLOUD_SECRETKEY,
},
profile: {
httpProfile: {
endpoint: "tcb.tencentcloudapi.com",
},
},
});
client
.CreateEnv({
PackageId: "baas_personal",
Alias: "tenant-a-env",
Resources: ["postgresql", "storage", "function"],
Period: 1,
})
.then(
(resp) => {
console.log(resp.EnvId);
},
(err) => {
console.error("error", err);
},
);
Obtaining credentials: use a CAM sub-user with CloudBase management permissions to log in to the Access Key console, create and save
SecretIdandSecretKey, and then configure them as theTENCENTCLOUD_SECRETIDandTENCENTCLOUD_SECRETKEYenvironment variables. The credentials should only be stored on the platform server side and must not be committed to code repositories or exposed to the frontend.For calling methods in other languages (Python, Java, Go, etc.), refer to the Cloud product SDK center.
The number of COS buckets for a single Tencent Cloud account has an account-level quota limit. When the platform needs to create more than 150 environments under a single account, pass ExternalStorage in CreateEnv to share the same COS bucket, to avoid reaching the quota and failing to create environments. For field descriptions, call examples and confirmation methods, see Appendix: Shared COS Bucket (ExternalStorage).
Response Parameters
After a successful call, the API returns the following key parameters:
| Parameter | Type | Description |
|---|---|---|
EnvId | String | Auto-generated environment ID |
TranId | String | Billing order number |
RequestId | String | Unique request ID |
Important: keep the returned
EnvIdsafe, as all subsequent operations require this environment ID. Purchase is an asynchronous operation, and it may take from a few seconds to a few minutes before the environment is created.
Wait for Provisioning and Confirm Status
Environment provisioning is asynchronous. Poll DescribeEnvs until the environment status becomes available. When the returned Status is NORMAL, the environment is ready, which usually takes 1-3 minutes. After confirmation, you can further query usage and billing:
- Query environment billing info: DescribeBillingInfo
- Query environment billing cycle: DescribeEnvAccountCircle
- Query environment quota usage: DescribeEnvLimit
Quota notes: COS resources and cloud functions (non-Shanghai regions) have account-level or region-level quota limits. When planning to create a large number of environments in batch, it is recommended to evaluate quotas with the CloudBase team in advance. When the number of environments under a single account exceeds 150 and the COS bucket quota is reached, you can create environments as described in Appendix: Shared COS Bucket (ExternalStorage).
Key Environment Information
During development, you will need the following key environment information, all of which can be obtained from the DescribeEnvs response:
| Information | Source field | Purpose |
|---|---|---|
| Environment ID | EnvId | Required parameter for all API calls |
| Database instance ID | Databases[0].InstanceId | Database operations |
| Storage bucket name | Storages[0].Bucket | File upload / download |
| Cloud Function namespace | Functions[0].Namespace | Function deployment and invocation |
Environment Lifecycle API Reference
- Create environment: CreateEnv
- Get environment list: DescribeEnvs
- Destroy environment: DestroyEnv
- Renew environment: RenewEnv
- Change package: ModifyEnvPlan
Large-Scale Creation: Environment Pool API
If your platform needs to quickly create CloudBase environments for a large number of users (such as SaaS multi-tenancy, consumer-facing platforms, etc.) and has high requirements for the throughput and response speed of environment creation, we provide the Environment Pool API, which supports pre-creating environments in batch and allocating them on demand, supporting the rapid creation and use of a massive number of CloudBase environments.
This capability requires contacting the CloudBase team to enable whitelist access. Please apply by submitting a Tencent Cloud ticket or contacting your account manager.
Next Steps
After the first environment is created, the next step is to issue API Keys for each user environment: