General FAQs

Last updated: 2020-06-04 14:15:08

    A function can run normally in the local system, but I am prompted that some dependencies cannot be found when I try to run it online. What should I do?

    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.

    After SCF is deployed to a VPC, how do I configure public network access?

    There are several ways for a VPC to access the public network. For more information, please see the NAT Gateway documentation.

    Is the IP used for SCF to access the public network random or fixed?

    It is random by default. You can also set a fixed public IP.

    What is the time zone in the SCF environment? How do I eliminate the impact of time zone differences?

    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.

    Is there any space in the environment for write operations?

    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 /tmp.

    What should I do if SCF returns a 504 error?

    1. Check the timeout period configured for the function and gateway and try to increase the gateway timeout period.
    2. Configure logging as instructed in API Gateway Log Management and analyze logs to identify specific causes.

    My TencentDB for Redis instance has only private network access. How do I connect SCF to it?

    To access resources in a VPC, please configure as instructed in VPC Communication.

    Why does the returned data format have extra quotation marks?

    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.

    Can the root account restrict a sub-account's permission to manipulate certain functions?

    Yes. For more information, please see Creating Sub-User and Granting It Permissions to Manipulate Certain Functions.

    How can SCF logs be delivered to COS?

    Forward logs to CLS as instructed in Connecting SCF Logs to CLS and configure CLS to deliver logs to COS.

    How does an application trigger a function directly?

    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.

    Can a function be used when its code or configuration is changed?

    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.

    Is there a limit to the number of functions that can be executed in a single run?

    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.

    What if a failure occurs when a function handles an event?

    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.

    What if an error occurs after there is no more space for write operations?

    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.

    Can I use threads and processes in my function code?

    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.

    Can I initiate network connections in my function code?

    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.

    What restrictions apply to function code?

    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.

    A jar package of Java is deployed on the backend of SCF. How can a WeChat Mini Program on the frontend call the deployed code?

    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.

    What events can trigger SCF functions?

    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.

    What languages does SCF support?

    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.

    Can I access the infrastructure where SCF runs?

    No. SCF manages the computing infrastructure on your behalf.

    How does SCF isolate code?

    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.

    Can SCF communicate with other Tencent Cloud products such as CVM or TencentDB?

    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.

    Does SCF reuse function instances?

    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.

    Why should I keep an SCF function stateless?

    Keeping the statelessness of the function allows the function to launch as many instances as needed to meet the requested rate.

    How do I troubleshoot?

    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.

    When I try to create a function by uploading a zip package, the system prompts "Function service creation failed. Please try again". What should I do?

    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.b, where 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 a.py and thirdfolder for compression.

    What if a timeout occurs?

    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.

    How do I scale a function?

    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.

    How do I allocate function computation resources?

    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.

    Can I use a local library?

    Yes. You can include your own code base in the function code and upload it to the platform as a zip package.

    What if the system prompts that "Resource limit exceeded for function" when a function is invoked?

    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.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help