Creating a Function
FunctionGraph manages the compute resources required for function execution. After editing code for your function, configure compute resources on the FunctionGraph console.
You can create a function from scratch or by using an existing template.
Creating a Function from Scratch
When creating a function from scratch, configure the basic and code information based on Table 1 and Table 2. The parameters marked with an asterisk (*) are mandatory.
For environment information, retain the default values, as shown in Table 4. After creating a function, you can modify its configuration based on Modifying Function Configurations.
|
Parameter |
Description |
|---|---|
|
*Function Name |
Function name. |
|
*App |
Select an existing app or define a new app to which the function belongs. You can create multiple functions under an app. |
|
*Enterprise Project |
Select an enterprise project to add the function to it.
NOTE:
If Enterprise Project Management Service (EPS) is not enabled, this parameter is unavailable. For details, see Enabling the Enterprise Project Function. |
|
Agency |
Used to delegate FunctionGraph to access other cloud services. For example, an agency is required when FunctionGraph accesses cloud services such as OBS or SMN. |
|
Description |
Description of the function. |
- For details on how to create an agency, see Creating an Agency.
- You can use no agency or specify the same agency for function configuration and execution. To reduce unnecessary performance consumption, select Specify an exclusive agency for function execution and set different agencies for function configuration and execution. Figure 1 shows the agency options.
Function configuration agency: Specify an agency with Distributed Message Service (DMS) or Data Ingestion Service (DIS) permissions for a function that needs to use DMS or DIS triggers. If such an agency is not specified or the specified agency does not exist, you cannot create DMS or DIS triggers for the function.
Function execution agency: After specifying such an agency, you can obtain a token and AK/SK from the context in the function handler for accessing other cloud services.
|
Parameter |
Description |
|---|---|
|
Runtime |
FunctionGraph supports Python 2.7, Python 3.6, Node.js 6.10, Node.js 8.10, Node.js 10.16, Node.js 12.13, Java 8, Go 1.8, Go 1.x, C# (.NET Core 2.0), C# (.NET Core 2.1), C# (.NET Core 3.1), and PHP 7.3. |
|
*Handler |
|
|
Code Entry Mode |
Method of entering the function code. For details about the supported code entry modes, see Table 3. |
|
Runtime |
Code Entry Mode |
Description |
|---|---|---|
|
Node.js 6.10/Node.js 8.10/Node.js 10.16/Node.js 12.13 |
Edit code inline |
Edit code in the code box. For more information, see Table 1. |
|
Upload ZIP file |
Click Select File and upload a local code package to FunctionGraph. The size of the ZIP file to be uploaded cannot exceed 10 MB. If it exceeds 10 MB, upload the ZIP file using an OBS bucket. |
|
|
Upload file from OBS |
Paste the link URL of the OBS bucket storing a code ZIP file. |
|
|
Python 2.7/Python 3.6 |
Edit code inline |
Edit code in the code box. For more information, see Table 1. |
|
Upload ZIP file |
Click Select File and upload a local code package to FunctionGraph. The size of the ZIP file to be uploaded cannot exceed 10 MB. If it exceeds 10 MB, upload the ZIP file using an OBS bucket. |
|
|
Upload file from OBS |
Paste the link URL of the OBS bucket storing a code ZIP file. |
|
|
Java 8 |
Upload ZIP file |
Click Select File and upload a local code package to FunctionGraph. The size of the ZIP file to be uploaded cannot exceed 10 MB. If it exceeds 10 MB, upload the ZIP file using an OBS bucket. |
|
Upload JAR file |
Click Select File and upload a local JAR file to FunctionGraph. The JAR file must contain at least one .class file. The size of the JAR file to be uploaded cannot exceed 10 MB. If it exceeds 10 MB, convert it into a ZIP file, and upload the ZIP file to OBS. |
|
|
Upload file from OBS |
Paste the link URL of the OBS bucket storing a code ZIP file. |
|
|
Go 1.8/Go 1.x |
Upload ZIP file |
Click Select File and upload a local code package to FunctionGraph. The size of the ZIP file to be uploaded cannot exceed 10 MB. If it exceeds 10 MB, upload the ZIP file using an OBS bucket. |
|
Upload file from OBS |
Paste the link URL of the OBS bucket storing a code ZIP file. |
|
|
C# (.NET Core 2.0)/C# (.NET Core 2.1)/C# (.NET Core 3.1) |
Upload ZIP file |
Click Select File and upload a local code package to FunctionGraph. The size of the ZIP file to be uploaded cannot exceed 10 MB. If it exceeds 10 MB, upload the ZIP file using an OBS bucket. |
|
Upload file from OBS |
Paste the link URL of the OBS bucket storing a code ZIP file. |
|
|
Custom |
Edit code inline |
Edit code in the code box. For more information, see Table 1. |
|
Upload ZIP file |
Click Select File and upload a local code package to FunctionGraph. The size of the ZIP file to be uploaded cannot exceed 10 MB. If it exceeds 10 MB, upload the ZIP file using an OBS bucket. |
|
|
Upload file from OBS |
Paste the link URL of the OBS bucket storing a code ZIP file. |
- When you write code in Python, do not name your package with the same suffix as a standard Python library, such as json, lib, and os. Otherwise, an error indicating a module loading failure will be reported.
- If the code to be uploaded contains sensitive information (such as account passwords), encrypt the code to prevent information leakage.
|
Parameter |
Description |
|---|---|
|
Memory (MB) |
Set the memory required for running the function on the Configuration tab page. |
|
*Initializer |
Set this parameter on the Code tab page if you have enabled initialization for the function. For all runtimes, the naming rules of function initializers are the same as those of function handlers. For example, for a Node.js, Python, or PHP function, set an initializer name in the format of [file name].[initialization function name]. |
|
*Initialization Timeout (s) |
Maximum duration the function can be initialized. Set this parameter on the Configuration tab page if you have enable initialization for the function. The value ranges from 1s to 300s. |
|
*Execution Timeout (s) |
Maximum duration the function can be executed. You can set this parameter on the Configuration tab page. Use asynchronous invocation for functions that take longer than 90s. The value ranges from 3s to 900s. |
- When creating a function, you can retain the default values for the memory, execution timeout, encryption settings, and environment variables. After creating the function, you can modify these settings according to Modifying Function Configurations.
- After a function is created, the default version is latest. Each function has the latest version.
- Functions are billed based on the number of function execution requests and function execution duration. Please set the memory and execution timeout based on service requirements.
Creating a Function Using a Template
FunctionGraph provides built-in function templates for typical scenarios. These templates contain code, configurations, environment, and trigger information. After you choose a template, FunctionGraph automatically loads the function information, enabling you to quickly create functions. For details, see Function Templates.
Last Article: Creating a Deployment Package
Next Article: Environment Variables

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.