Skip to main content

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:

First-time activation

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:

ParameterDescription
PackageIdPackage ID; see the common packages table below; can be obtained via DescribeBaasPackageList
AliasEnvironment 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
ResourcesResource types needed in the environment; see the table below
PeriodPurchase duration (months), range 1-12 or 24, default 1
RenewFlagAuto-renewal flag: NOTIFY_AND_AUTO_RENEW (notify and auto-renew) / NOTIFY_AND_MANUAL_RENEW (notify without auto-renewal, default)
TagsEnvironment tags, used for permission isolation and resource grouping; it is recommended to tag by tenant ID and business line
EnableOverrunOverrun 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
ExternalStorageShared 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 IDPackage nameApplicable scenario
baas_integrationIntegrationPlatform-type customers that need to create a large number of environments under one account
baas_personalPersonalGetting started trial, personal development
baas_pf_standardStandardSmall teams, production environments
baas_pf_enterpriseEnterpriseEnterprise-level business

Resources values:

ValueDescription
postgresqlPostgreSQL database (relational database, supports SQL)
storageObject storage (cloud storage)
functionCloud 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 SecretId and SecretKey, and then configure them as the TENCENTCLOUD_SECRETID and TENCENTCLOUD_SECRETKEY environment 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.

More than 150 environments under a single account?

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:

ParameterTypeDescription
EnvIdStringAuto-generated environment ID
TranIdStringBilling order number
RequestIdStringUnique request ID

Important: keep the returned EnvId safe, 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:

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:

InformationSource fieldPurpose
Environment IDEnvIdRequired parameter for all API calls
Database instance IDDatabases[0].InstanceIdDatabase operations
Storage bucket nameStorages[0].BucketFile upload / download
Cloud Function namespaceFunctions[0].NamespaceFunction deployment and invocation

Environment Lifecycle API Reference

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:

Get environment API Key