SCF offers multiple function creation methods. This document describes how to create a function through the console and command line tool.
Creating functions via the console
- Log in to the SCF console and click Function Service on the left sidebar.
- Select the region and namespace where to create a function at the top of the Functions page and click Create to enter the function creation process as shown below:
- On the Create function page, select a function creation method as needed.
- Template: You need to enter the required function name and use configuration items in the function template to create the function.
- Create from scratch: You need to enter the required function name and runtime environment to create the function.
- Use TCR image: You can create a function based on a TCR image. For more information, see Usage.
- Configure the basic information of the function.
- Add a tag in Fuzzy search to find a template as shown below:
- Select the template and click Next.
- Enter the basic information of the function.
- Function name: The function name is automatically populated by default and can be modified as needed.
- Region: The region is automatically populated by default and can be modified as needed.
- Time zone: SCF uses the UTC time by default, which you can modify by configuring the
TZ
environment variable. After you select a time zone, the TZ
environment variable corresponding to the time zone will be added automatically.
Enter the basic information of the function.
- Function type: Select Event-triggered function or HTTP-triggered function.
- Event-triggered function: Receives JSON-formatted events from TencentCloud API or various triggers to trigger the function execution. For more information, see Basic Concepts.
- HTTP-triggered function: Directly receives HTTP requests to trigger the function execution in web service scenarios. For more information, see Function Overview.
- Function name: The function name is automatically populated by default and can be modified as needed.
- Region: The region is automatically populated by default and can be modified as needed.
- Runtime environment: The runtime environment is automatically populated by default and can be modified as needed.
- Time zone: SCF uses the UTC time by default, which you can modify by configuring the
TZ
environment variable. After you select a time zone, the TZ
environment variable corresponding to the time zone will be added automatically.
Enter the basic information of the function.
- Function type: Select Event-triggered function or HTTP-triggered function.
- Event-triggered function: Receives JSON-formatted events from TencentCloud API or various triggers to trigger the function execution. For more information, see Basic Concepts.
- HTTP-triggered function: Directly receives HTTP requests to trigger the function execution in web service scenarios. For more information, see Function Overview.
- Function name: The function name is automatically populated by default and can be modified as needed.
- Region: Select the region where the function is deployed, which must be the same as the region where the image repository is located.
- Time zone: SCF uses the UTC time by default, which you can modify by configuring the
TZ
environment variable. After you select a time zone, the TZ
environment variable corresponding to the time zone will be added automatically.
- Configure the function code.
The runtime environment and execution method are automatically populated by default as shown below:
Select the function code submitting method and execution method as shown below:
- Submitting method: Online editing, Local ZIP file, Local folder, and Upload a ZIP pack via COS are supported.
- For scripting languages: You can directly use the function code editor.
- For non-scripting languages: You can submit the function code by uploading a zip package or through COS and then edit it.
- Execution: It specifies the starting file and function while invoking the cloud function. For more information, see Function Overview.
Enter the image information as shown below:
- Image: Select an image already built in the image repository in the current region.
- ENTRYPOINT: (Optional) Set the startup command of the container. Enter an executable command (such as python). If it's left blank, the Entrypoint in the Dockerfile is used.
- CMD: (Optional) Set the startup parameters of the container. Separate each parameter with a space. If it's left blank, the CMD in the Dockerfile is used.
- Image acceleration: It is disabled by default. After it is enabled, SCF will pulling image much more quickly. It takes over 30 seconds to enable this option; therefore, wait patiently.
- In Log configuration, choose whether to enable log delivery as shown below:
Log delivery is disabled by default. After it is enabled, the execution logs of the function can be delivered to the specified location in real time. For more information, see Log Delivery Configuration. Note
Currently, you cannot select the log template for image-based functions and HTTP-triggered functions.
- In Advanced configuration, configure the environment, permission, layer, and network of the function as needed. For more information, see Function Overview.
- In Trigger configurations, choose whether to create a trigger. If you select Custom, see Trigger Overview.
- Click Complete. You can view the created function on the Functions page.
Creating Function on CLI
You can create a function as needed in more ways as detailed below:
Was this page helpful?