Creating an Event Function
Creating a function is the first step in using FunctionGraph. To trigger tasks via cloud events, create an event function and configure code, network, and triggers as needed. This section shows how to create one via the console.
For details about the comparison between event functions and HTTP functions, see Table 1.
Item |
Event Function |
HTTP Function |
---|---|---|
Usage |
It is used to process files and data flows, which can be triggered by events of various cloud products. It is also used to process asynchronous requests and track and save the status of each asynchronous invocation. |
It supports popular web application frameworks and AI projects. You can access the functions using a browser or by calling a URL. |
Scenario |
|
|
Video Tutorial
This video shows how to create a function from scratch and test the function.
Notes and Constraints
By default, an account can create a maximum of 400 functions. To increase the quota, submit a service ticket.
Prerequisites
- To perform the operations described in this section, ensure that you have the FunctionGraph Administrator permissions, that is, the full permissions for FunctionGraph. For more information, see Permissions Management.
- To access other cloud services such as Log Tank Service (LTS) and Virtual Private Cloud (VPC), create an agency by referring to Creating a Function Agency. If FunctionGraph does not need to access other cloud services, you do not need to create or select an agency.
- To enable FunctionGraph to access resources in a VPC, create a VPC and subnet by referring to Creating a VPC and a Subnet.
Creating an Event Function
- Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
- On the Function List page, click Create Function in the upper right corner.
- Select Create from scratch and configure basic information by referring to Table 2 and advanced settings by referring to Table 3 as shown in Figure 1.
Table 2 Basic information parameters Parameter
Description
Example Value
Function Type
Select Event Function.
An event function is triggered by a specific event, which is usually a request event in JSON format.
Event Function
Region
Select the region where the function is located.
Regions are geographic areas isolated from each other. Resources are region-specific and cannot be used across regions through internal network connections. Select a region near you to ensure the lowest latency possible.
CN East-Shanghai1
Function Name
Enter a function name. The naming rules are as follows:
- Consists of 1 to 60 characters, and can contain letters, digits, hyphens (-), and underscores (_).
- Starts with a letter and ends with a letter or digit.
FG-demo
Enterprise Project
Select the enterprise project to which the function belongs. Enterprise projects let you manage cloud resources and users by project.
The default value is default. You can select the created enterprise project.
If the Enterprise Management service is not enabled, this parameter is unavailable. For details, see Enabling the Enterprise Project Function.
default
Agency
Select an agency for the function. An agency is used to authorize FunctionGraph to access other cloud services. If FunctionGraph does not access any cloud service, you do not need to select an agency.
By default, Use no agency is used. You can select an existing agency.
If no default agency is available, FunctionGraph allows you to quickly create a default agency named fgs_default_agency. For details, see Default Agency.
fgs_default_agency
Permission Policies
This parameter is displayed only when an agency is selected.
After an agency is selected, the permission policies associated with the agency are displayed. For details about how to adjust them, see Modifying a Function Agency.
DIS User; SWR Admin; fgs_default_region_role; fgs_default_global_role
Runtime
Select a runtime to compile the function.
For details about the runtimes supported by FunctionGraph, see Supported Runtimes.
- CloudIDE supports only online editing of Node.js, Python, PHP, and custom runtimes.
- After a function is created, the runtime language cannot be changed.
Node.js 16.17
Figure 2 Advanced setting parametersTable 3 Advanced setting parameters Parameter
Description
Example Value
Public Access
If this feature is enabled, functions can access services on the public network through the default NIC. The public network access bandwidth is shared among users and applies only to test scenarios.
Enabled
VPC Access
To enable this feature, you need to configure an agency with VPC management permissions. If you select Use no agency in the Basic Information area, this feature cannot be enabled.
If this feature is enabled, functions will use the NIC bound to the configured VPC for network access, and the default NIC of FunctionGraph will be disabled. That is, the Public Access parameter does not take effect.
After this feature is enabled, you can select the VPC and subnet that the function needs to access.
Disabled
Collect Logs
After it is enabled, logs generated during function execution will be reported to LTS.
CAUTION:LTS will be billed on a pay-per-use basis. For details, see LTS Pricing Details.
Configure the following parameters:
- Log Configuration
- Auto: Use the default log group and log stream.
- Custom: Select the log group and log stream you created.
- Log Tag
You can filter function logs on the LTS console by tag. For details, see Log Management.
A tag key or value can contain a maximum of 64 characters, including only digits, letters, underscores (_), and hyphens (-). A maximum of 10 tags can be added.
Disabled
Static Encryption with KMS
This parameter can be configured only in the LA-Sao Paulo1 region.
Determine whether to use KMS-based static encryption for function code.
CAUTION:DEW is billed by the pay-per-use mode. For details, see DEW Billing.
You can select the following encryption types:
- functiongraph/default (default): The function automatically creates a default key in DEW under your account.
If you use the default key for encryption and decryption for the first time, ensure that the function agency has the following permissions: kms:dek:decrypt, kms:dek:create, kms:cmk:create, kms:cmk:get, and kms:cmk:list.
- Customer master key (CMK): You can select a created key to encrypt the function code. For details about how to create a customer master key, see Creating a Custom Key. To use customer master key, ensure that the function agency has the following permissions: kms:dek:decrypt, kms:dek:create, kms:cmk:get and kms:cmk:list.
CAUTION:
If you select Customer master key (CMK), do not delete the CMK used for function encryption in DEW. Otherwise, the function execution will fail because encrypted data cannot be decrypted.
Configure the agency permission policy on the IAM console by referring to Creating a Custom Policy in JSON View.
functiongraph/default (default)
- After the configuration is complete, click Create Function. The function details page is displayed, and a message is displayed in the upper part of the page, indicating that the function is created.
- After the function is created, configure it based on service requirements by referring to Configuring Functions.
Helpful Links
- For different scenarios, you can create event and HTTP functions, compile functions using built-in runtimes, custom runtimes, or custom images, and allocate GPU compute resources to functions. For details about how to select a function type, see Function Selection.
- You can create functions using APIs. For details, see Creating a Function.
- For FAQs about function creation, see Function Creation FAQs.
- For details about how to create a simple event function, see Creating a Function from Scratch and Executing the Function and Creating an Event Function Using a Container Image and Executing the Function.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot