Step 2. Create a Thumbnail function and test it

Last updated: 2020-05-09 18:24:21

    Creating Thumbnail Function

    1. Log in to the SCF Console and select Functions on the left sidebar.

    2. Select the Guangzhou region at the top of the "Functions" page and click Create.

    3. Enter the following parameter information on the "Create Function" page and click Next as shown below:

      • Function Name: enter Thumbnail.
      • Runtime Environment: select Python 2.7.
      • Creation Method: select Template function.
      • Template Search: enter "image compression" to search and select the image compression template whose language is Python 2.7 in the results.
        Move the cursor over the template function to view its details. The download operation is supported.
    4. Keep the default configuration and click Complete to complete the function creation.

    5. When using this template function, you need to modify the configuration information in the function code as prompted.
      In the code box on the Function Code tab, replace appid, secret_id, secret_key, region, and resized_bucket with your APPID, SecretId, SecretKey, region, and resized_bucket and click Save to complete the creation.

      • The APPID can be obtained on the Account Info page in the console.
      • The SecretId and SecretKey can be obtained on the API Key Management page in the console.

    Configuring COS Trigger

    1. On the "Functions" page, select a function name to enter the function management page.
    2. Select the Triggers tab and click Add Trigger to add a COS trigger for the function.
    3. In the "Add Trigger" module, set the following parameters and click Save.
      The main parameter information is as follows. Keep the remaining parameters as default:
      • Trigger Type: select COS trigger.
      • COS Bucket: select the bucket mybucket created in Step 1.
      • Event Type: select Create All.

    Testing Function

    1. Switch to the COS Console, select the created bucket mybucket, click Upload File, and select a random .jpg or .png image for upload.
    2. Switch to another COS bucket mybucket-resized, check whether there is a file with the same name generated, download it, and compare the size of the two images.
    3. Log in to the SCF Console to view the execution result. You can see the printed log information in Logs.

    Relevant Operations

    Viewing and getting function code

    1. After you successfully create a function, you can select Function Code to enter the function code details page.
    2. On this page, you can view and edit the function code or click Download in the top-right corner to download the function code package or YAML file.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help