key-value
pairs. Enter the required environment variable key in the first input box and the required value in the second one. Note that the value of key
or value
can contain 2–64 bytes of letters, digits, and underscores and must begin with a letter.Environment
environment variable directly under the function in serverless.yml
and run the scf deploy
command to deploy it to the cloud as shown below:component: scf # Component name, which is required. It is `scf` in this examplename: scfdemo # Component instance name, which is required# Component parameter configurationinputs:name: scfdemo # Function name, which is `${name}-${stage}-${app}` by defaultnamespace: default# 1. Default format. Create a specifically named COS bucket and upload itsrc: ./srctype: event # Function. Valid values: event - event-triggered (default), web - HTTP-triggeredhandler: index.main_handler # Entry (valid if the function is event-triggered)runtime: Nodejs10.15 # Runtime environment, which is Nodejs10.15 by defaultregion: ap-guangzhou # Function regiondescription: This is a function in ${app} application.memorySize: 128 # Memory size in MBtimeout: 20 # Function execution timeout period in secondsinitTimeout: 3 # Initialization timeout period in secondsenvironment: # Environment variablevariables: # Environment variable objectTEST1: value1TEST2: value2
key=value
.key
. The following is the sample codes for reading and printing the value of this environment variable in different runtime environments.import osvalue = os.environ.get('key')print(value)
var value = process.env.keyconsole.log(value)
TENCENTCLOUD_SESSIONTOKEN
, TENCENTCLOUD_SECRETID
, and TENCENTCLOUD_SECRETKEY
), the way to read the environment variables is as follows:System.out.println("value: "+ System.getProperty("key"));
System.out.println("value: "+ System.getenv("key"));
import
"os"
var
value
string
value
=
os
.
Getenv
(
"key"
)
$value = getenv('key');
Key
and Value
of built-in environment variables in the current runtime environment are as shown in the table below:Environment Variable Key | Specific Value or Value Source |
TENCENTCLOUD_SESSIONTOKEN | {Temporary SESSION TOKEN} |
TENCENTCLOUD_SECRETID | {Temporary SECRET ID} |
TENCENTCLOUD_SECRETKEY | {Temporary SECRET KEY} |
_SCF_SERVER_PORT | 28902 |
TENCENTCLOUD_RUNENV | SCF |
USER_CODE_ROOT | /var/user/ |
TRIGGER_SRC | Timer (if a timer trigger is used) |
PYTHONDONTWRITEBYTECODE | x |
PYTHONPATH | /var/user:/opt |
CLASSPATH | /var/runtime/java x:/var/runtime/java x/lib/*:/opt (`x` is 8 or 11) |
NODE_PATH | /var/user:/var/user/node_modules:/var/lang/node x/lib/node_modules:/opt:/opt/node_modules (`x` is 16, 14, 12, 10, 8, or 6) |
PHP_INI_SCAN_DIR | /var/user/php_extension:/opt/php_extension |
_ | /var/lang/python3/bin/python x (`x` is 37, 3, or 2) |
PWD | /var/user |
LOGNAME | qcloud |
LANG | en_US.UTF8 |
LC_ALL | en_US.UTF8 |
USER | qcloud |
HOME | /home/qcloud |
PATH | /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
SHELL | /bin/bash |
SHLVL | 3 |
LD_LIBRARY_PATH | /var/runtime/java x:/var/user:/opt (`x` is 8 or 11) |
HOSTNAME | {host id} |
SCF_RUNTIME | Function runtime |
SCF_FUNCTIONNAME | Function name |
SCF_FUNCTIONVERSION | Function version |
TENCENTCLOUD_REGION | Region |
TENCENTCLOUD_APPID | Account APPID |
TENCENTCLOUD_UIN | Account UIN |
TENCENTCLOUD_TZ | Time zone, which is UTC currently |
Was this page helpful?