Help Center > > User Guide> Advanced Operations> Function Templates

Function Templates

Updated at: Oct 25, 2019 GMT+08:00

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

Template Description

FunctionGraph provides 24 function templates (18 basic and 6 advanced), which are described in Table 1.

Table 1 Template description

Template Type

Template Name

Description

Basic templates

context-class-introduction

Obtains a temporary credential (such as AK, SK, and token) required for accessing other HUAWEI CLOUD services.

file-download-from-obs

Downloads files from a specified OBS bucket, reads the files, and returns the size of each file.

file-upload-to-obs

Uploads local files to a specified OBS bucket.

read-dms-message

Periodically pulls messages from a specified DMS consumer group, and prints the content and attributes of the messages.

read-smn-message

Runs in response to SMN messages to print their content and subjects.

read-apig-message

Runs in response to API requests, and demonstrates how to display different types of content, such as HTML pages and JSON structures.

read-lts-message

Runs in response to LTS events to print log group IDs, log topic IDs, and log content.

image-classify

Runs in response to images uploaded to a specified OBS bucket, and stores the images into different buckets based on the image sizes.

Advanced templates

image-tag

Builds a serverless image classification system based on the EI service. Calls the image classification interface of the EI service to classify images. Uses an OBS trigger to classify and process every image uploaded to a specified bucket, and to automatically sort the images into corresponding directories.

porn-image-analysis

Builds a real-time serverless pornographic image identification system based on the EI service. Calls the pornographic image identification interface of the EI service to identify images in real time through an OBS trigger.

porn-image-analysis

Builds a real-time serverless pornographic image identification system based on the EI service. Calls the pornographic image identification interface of the EI service to identify images in real time through an OBS trigger.

voice-analysis

Builds a serverless speech recognition system based on the EI service. Connects to the EI service, calls the speech recognition interface to convert WAV speeches into texts, and provides an interface through an APIG trigger for external use.

Template Usage

Creating a Function and Trigger

  1. Log in to the FunctionGraph console, and choose Templates in the navigation pane.
  2. On the Templates page, find read-smn-message, and click Configure, as shown in Figure 1.

    The code, configurations, and trigger information of the template are loaded on the Create Function page.

  3. Enter function name read-smn-message.
  4. Select SMN topic serverless-Test.
    Figure 1 Selecting a function template
  5. Click Create Now. A function and trigger are created, as shown in Figure 2.
    Figure 2 Created SMN trigger

Triggering a Function

  1. Log in to the SMN console. In the navigation pane, choose Topic Management > Topic.
  2. Click serverless-Test.
  3. On the topic details page that is displayed, click Publish Message, as shown in Figure 3.
    Figure 3 Publishing a message
  4. In the Publish Message dialog box, configure the message information according to Table 2. The parameters marked with an asterisk (*) are mandatory.
    Table 2 Parameters required for publishing a message

    Parameter

    Description

    Message Subject

    Enter SMN-Test.

    *Message Type

    Select Text.

    *Message

    Enter hello.

    For details about the parameters required for publishing a message, see Publishing Messages to a Topic.

  5. Click OK.

    After message publishing, the function is triggered automatically. For details about example events, see Supported Event Sources.

  6. Return to FunctionGraph to view function logs.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel