A common reason is that third-party dependencies have not been packaged and uploaded to the online environment. You need to put the third-party libraries that the function depends on into the function directory and package and upload them along with the function code.
There are several ways for a VPC to access the public network. For more information, please see the NAT Gateway documentation.
It is random by default. You can also set a fixed public IP.
UTC (GMT+0) is used in the SCF operating environment, which is 8 hours behind Beijing time.
You can use a time processing library or code package in your programming language to identify UTC time zone and convert it to Beijing time (GMT+8). You can also set the
TZ=Asia/Shanghai environment variable to specify the time zone.
Yes. A function has a temporary disk space of 500 MB (
/tmp) during execution. You can perform read and write operations or create subfolders in this space while executing the code, but data written in this space will not be retained after the function is executed.
- The temporary disk spaces of different instances are isolated, i.e., each instance has its own independent temporary space.
- In the operating environment, all directories are read-only except for
To access resources in a VPC, please configure as instructed in VPC Communication.
API Gateway considers the returned result from SCF as in JSON format by default. You can select integrated response in function configuration as instructed in Integrated Response and Passthrough Response to solve this problem. Please note that after integrated response is enabled, the data structure needs to be returned according to the specification.
Yes. For more information, please see Creating Sub-User and Granting It Permissions to Manipulate Certain Functions.
The function can be triggered directly by calling the
Invoke API of SCF. The owner of the function or an account that has the permission to call the function's
Invoke API can make calls directly.
Yes. There is a short window period of less than 1 minute in general when the function is updated, during which the request will be implemented by either the old or new function code.
SCF supports high numbers of concurrent function instances. However, it has a default security threshold, that is, up to 300 concurrent executions are allowed per function. To increase the limit, please submit a ticket.
In case of failure, a function that makes sync invocations will return the exception information, while a function that makes async invocations will automatically retry 3 times on the backend.
If data is written to the
/tmp directory continuously and the instance is used constantly due to frequent invocations, the directory may be full and write is no longer possible.
If this happens, check the state of writes in the directory and use code to delete temporary files no longer needed to free up the space.
Yes. You can use normal programming language and operating system features, such as creating additional threads and processes. Resources allocated to the function, including memory, execution duration, disk, and network, are shared by the threads or processes it uses.
Yes. You can use normal programming language and operating system features, such as initiating TCP and UDP connections. Through relevant language libraries, you can also perform operations such as connecting to databases and accessing APIs.
We try not to impose restrictions on normal activities at the programming language and operating system levels, but certain activities such as inbound network connection are disabled.
API Gateway can be used to this end. Configure the backend of API Gateway as a function and then call the gateway API to trigger the function. For detailed directions, please see How to Create Triggers and API Gateway Trigger.
Currently, triggering by manual triggers (APIs), timer triggers, COS, CMQ, and API Gateway is supported, and more triggering methods will be available in the future.
Currently, it supports Python 2.7 and 3.6, Node.js 6.10, 8.9, and 10.15 & 12.16, Java 8, PHP 5 and 7, and Go. More languages will be supported in the future.
No. SCF manages the computing infrastructure on your behalf.
Each function runs in its own unique environment and has its own resources and file system. SCF uses the same technology as CVM to provide security and isolation at the infrastructure and execution levels.
Yes. When you create or modify a function, select VPC configuration and deploy the function in the same VPC as the CVM or TencentDB instance.
To improve performance, SCF will retain your function instance for a certain period of time and reuse it for subsequent requests. However, your code should not assume that this action always happens.
Keeping the statelessness of the function allows the function to launch as many instances as needed to meet the requested rate.
SCF has a logging function. Each invocation will output its log to the logs window in the console. The log records the resources consumed by the function during each use, the log in the code, and the platform invocation information. You can easily insert troubleshooting-related log statements into your code.
A common reason is that the function's execution method cannot find the corresponding executable file or function entry in the zip package, or an outer folder is included during compression. The execution method format is
a is the name of the
py file and
b is the method name in the code.
If a file named
a.py cannot be found in the root directory of the unzipped folder, the system will prompt that "The function code cannot be displayed as the file specified by the execution method cannot be found in the zip package of the code".
For example, if a folder structure is as follows:
--RootFolder ----SecondFolder ------a.py ------thirdfolder --------sth.json
When you create the zip package, if
SecondFolder is zipped, the error above will occur; instead, you should select
thirdfolder for compression.
Please set the timeout period to a larger value (up to 300) and test the function again. If it still times out, please check whether there are excessive input data and computation, loops that cannot be jumped out, or prolonged sleeps in the log of your code.
You do not have to care about function scaling as the SCF platform will automatically do so on your behalf. Whenever a function request is received, SCF will quickly locate the free capacity and execute your code. Since your code is stateless, as many instances as needed can be launched without lengthy delays in deployment and configuration.
You can select the amount of memory allocated to a function, and the CPU and other resources will be allocated proportionally. For example, if you select 256 MB of memory, the CPU allocated to the function will be approximately twice that allocated for 128 MB of memory.
Yes. You can include your own code base in the function code and upload it to the platform as a zip package.
A common reason is that the function concurrency exceeds the quota limit. You can calculate the required amount of function concurrency with the formula "function concurrency = QPS (number of requests per second) * function execution duration (in seconds)".
For example, if QPS = 100 and function execution duration = 100 ms, then the actual required function concurrency will be 100 * 0.1 = 10; if the concurrency exceeds the upper limit, you can increases the limit by submitting a ticket.