Function Compute provides various function templates. You can use function templates to create functions in the Function Compute console with efficiency. For example, you can create web crawler functions, functions used to automatically classify images, and functions used to access Object Storage Service (OSS). This topic describes how to use a function template to create a web crawler function in the Function Compute console.

Prerequisites

  • A service is created in Function Compute. For more information, see Create a service.
  • The AliyunOSSFullAccess and AliyunLogFullAccess permission policies are attached to the service-linked role of Function Compute. For more information, see Configure service permissions.

Procedure

  1. In the top navigation bar, select a region.
  2. In the left-side navigation pane, click Services and Functions.
  3. On the Services and Functions page, click Create Function. In the Template Function section, move the pointer over image-crawler and click Configure and Deploy.
    choose template
  4. In the Configure Function section, set the parameters and click Create.
    enter parameter value

    The following table describes the parameters.

    Parameter Description
    Service Name The name of the service.
    • If you have created at least one service, select an existing service from the drop-down list.
    • If you have not created a service, enter a new service name. The system automatically creates a service with the specified service name.
    Function Name The name of the function.
    Runtime The runtime environment of the function. You do not need to set this parameter.
    Instance Type The instance type for the function. Valid values:
    • Elastic Instance
    • Performance Instance
    For more information, see Instance specifications and usage modes.
    Function Handler The name of the function handler. You do not need to set this parameter.
    Memory The memory that is required to execute the function.
    Timeout The timeout period. Unit: seconds. Default value: 3.

    If the execution of the function is not complete within the specified timeout period, the function fails to be executed.

    Single Instance Concurrency The number of requests that can be concurrently processed by a single instance.
    After the function is created, the Code tab appears.
  5. On the Code tab, replace <your region> and <your bucket name> in the code with the information about your OSS bucket. You can also modify other parts of the code in the code editor.
    modify code
  6. Click Event. In the Test Event panel, modify the event parameter and click OK.
    Test Event
  7. Click Invoke to view the execution result of the function.
    Execution result of the function