Environment
tcb.SYMBOL_CURRENT_ENV
Field description: This field is used during initialization to specify the environment for requesting the current cloud function.
Note: Starting from v3, if the
env
parameter is not specified during initializationinit({})
, the current cloud function environment ID will be used by default instead of the default CloudBase environment. To use the default CloudBase environment, specifyinit({env: tcb.SYMBOL_DEFAULT_ENV})
.
Sample code
import tcb from '@cloudbase/node-sdk'
// Initialize using the current cloud function environment
const app = tcb.init({ env: tcb.SYMBOL_CURRENT_ENV })
exports.main = async (event, context) => {
//Business logic.
}
parseContext
1. Interface Description
Function: Parse environment variables in the cloud function environment. (Parameters can be obtained directly from the cloud function's entry parameter context
.)
Interface declaration: parseContext(context): Object
2. Input Parameters
Field | Type | Required | Description |
---|---|---|---|
memory_limit_in_mb | Number | Yes | Cloud function memory limit |
time_limit_in_ms | Number | Yes | Execution time limit |
request_id | String | Required | Request ID |
environ | String | Yes | Environment variable string |
function_version | String | Yes | Cloud function version |
function_name | String | Yes | Cloud function name |
namespace | String | Yes | Namespace |
3. Response
Field | Type | Required | Description |
---|---|---|---|
memory_limit_in_mb | Number | Yes | Cloud function memory limit |
time_limit_in_ms | Number | Yes | Execution time limit |
request_id | String | Required | Request ID |
environ | Object | Yes | Environment variable object (containing user-defined custom environment variable values) |
function_version | String | Yes | Cloud function version |
function_name | String | Yes | Cloud function name |
namespace | String | Yes | Namespace |
4. Sample Code
import tcb from '@cloudbase/node-sdk'
exports.main = async (event, context) => {
// The context parameter is taken from the context object of the cloud function's entry function handler
const envObj = tcb.parseContext(context)
// Print cloud function environment variables
console.log(envObj)
}