Creating an Event Function
Overview
A function is customized code for processing events. You can create a function from scratch and configure the function based on site requirements.
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 a template or container image.
When creating a function from scratch, configure the basic and code information based on Table 1. The parameters marked with an asterisk (*) are mandatory.
Each FunctionGraph function runs in its own environment and has its own resources and file system.
Prerequisites
- You must be familiar with the programming languages supported by FunctionGraph. For details, see Supported Programming Languages.
- You have created a deployment package. For details, see Creating a Deployment Package.
- (Optional) You have created an agency. For details, see Configuring Agency Permissions.
Procedure
- 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.
- Click Create from scratch and configure the function information by referring to Table 1. The parameters marked with an asterisk (*) are mandatory.
Figure 1 Creating a function from scratch
Table 1 Basic information Parameter
Description
* Function Type
- Event functions: triggered by triggers.
- HTTP functions: triggered once HTTP requests are sent to specific URLs.
NOTE:
- HTTP functions do not distinguish between programming languages. The handler must be set in the bootstrap file. You can directly write the startup command, and allow access over port 8000.
- HTTP functions support APIG and APIC triggers only.
- For details about how to use HTTP functions, see Creating an HTTP Function.
*Region
Select a region where you will deploy your code.
*Function Name
Name of the function, which must meet the following requirements:
- 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.
Agency
An agency is required if FunctionGraph accesses other cloud services. For details on how to create an agency, see Configuring Agency Permissions.
No agency is required if FunctionGraph does not access any cloud services.
*Enterprise Project
Select a created enterprise project and add the function to it. By default, default is selected.
NOTE:If Enterprise Project Management Service (EPS) is not enabled, this parameter is unavailable. For details, see Enabling the Enterprise Project Function.
Runtime
Select a runtime to compile the function.
NOTICE:CloudIDE supports Node.js, PHP, and Python only.
- Click Create Function. On the displayed Code tab page, continue to configure the code.
Configuring Code
- You can deploy the code based on the runtime you select. For details, see Creating a Deployment Package. After the deployment is complete, click Deploy.
As shown in the following example, to deploy code in Node.js 10.16, you can edit code inline, upload a local ZIP file, or upload a ZIP file from OBS.
Figure 2 Deploying code
- You can modify the code and click Deploy to deploy the code again.
Viewing Code Information
- View code attributes.
- View basic information.
Configuring Basic Settings shows the default memory and execution timeout in each runtime. You can click Edit to switch to the Basic Settings page and modify Handler, Memory (MB), and Execution Timeout (s) as required. For details, see Figure 4.
Once a function is created, the runtime cannot be changed.
Table 2 Default basic information of each runtime Runtime
Default Basic Information
Java
Memory (MB): 512
Handler: com.demo.TriggerTests.apigTest
Execution Timeout (s): 15
Node.js
Memory (MB): 128
Handler: index.handler
Execution Timeout (s): 3
Custom
Memory (MB): 128
Handler: bootstrap
Execution Timeout (s): 3
PHP
Memory (MB): 128
Handler: index.handler
Execution Timeout (s): 3
Python
Memory (MB): 128
Handler: index.handler
Execution Timeout (s): 3
Go 1.x
Memory (MB): 128
Handler: handler
Execution Timeout (s): 3
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