Updated on 2023-11-21 GMT+08:00

Creating a Function Using a Template

Introduction

FunctionGraph provides templates to automatically complete code and running environment configurations when you create a function, helping you quickly build applications.

Step 1: Prepare the Environment

To perform the operations described in this section, ensure that you have the FunctionGraph FullAccess permissions, that is, all permissions for FunctionGraph. For more information, see Permissions Management.

Step 2: Create a Function

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. Click Create Function in the upper right corner and choose Select template.
  3. Select the template shown in Figure 1 and click Configure.
    Figure 1 Selecting a template
  1. Set Function Name to context, select any agency from the Agency drop-down list, retain default values for other parameters, and click Create Function.
    • If no agency is configured, the following message will be displayed when the function is triggered:
      Failed to access other services because no temporary AK, SK, or token has been obtained. Please set an agency.
    Figure 2 Setting basic information

Step 3: Test the Function

  1. On the function details page, click Test. In the displayed dialog box, create a test event.
  2. Select blank-template, set Event Name to test, and click Create.
    Figure 3 Configuring a test event

Step 4: View the Execution Result

Click Test and view the execution result on the right.

  • Function Output: displays the return result of the function.
  • Log Output: displays the execution logs of the function.
  • Summary: displays key information of the logs.

A maximum of 2 KB logs can be displayed. For more log information, see Querying Function Logs.

Step 5: View Monitoring Metrics

On the function details page, click the Monitoring tab.

  • On the Monitoring tab page, choose Metrics, and select a time range (such as 5 minutes, 15 minutes, or 1 hour) to query the function.
  • The following metrics are displayed: invocations, errors, duration (including the maximum, average, and minimum durations), and throttles.

Step 6: Delete a Function

  1. On the function details page, choose Operation > Delete Function in the upper right corner.
  2. In the displayed dialog box, click OK to release resources.