Custom Invitation

Last updated: 2020-09-01 17:16:22

    Overview

    This document describes how to use SCF in combination with API Gateway to customize an invitation, so that you can generate an invitation simply by entering the guest name.

    Directions

    Creating function

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

    2. At the top of the "Functions" page, select the Guangzhou region and click Create to enter the function creating page.

    3. Create a function as follows in "Basic Info" on the "Create Function" page and click Next as shown below:

      • Function Name: enter a custom name. This document uses test as an example.
      • Runtime Environment: select "Python 2.7".
      • Create Method: select Function Template.
      • Fuzzy Search: enter "Custom invitation" and search.
        Click Learn More in the template to view relevant information in the "Template Details" pop-up window, which can be downloaded.
    4. On the "Function configuration" page, keep the default configuration and click Complete.

    Creating gateway trigger

    A gateway trigger is used to pass the name of an invitation to the function through an API call. The specific steps are as follows:

    1. Select Trigger Management on the left of the "Function configuration" page and click Create a Trigger.
    2. In the "Create a Trigger" pop-up window, add an API gateway trigger for the function.

    The main parameters are as follows. Keep the remaining parameters as default:

    • Trigger Method: select "API Gateway Trigger".
    • API Service Type: select "Create API Service".
    • Enable Integration Response: check this option.
      1. Click Submit.

    Creating bucket

    A bucket is used to store custom invitations. The specific steps are as follows:

    1. Log in to the COS Console and select Bucket List on the left sidebar.
    2. Click Create Bucket on the "Bucket List" page.
    3. In the "Create Bucket" pop-up window, create a bucket.
      .
      The main parameter information is as follows. Keep the remaining parameters as default:
      • Name: enter a custom name. This document uses test as an example.
      • Region: select "Guangzhou".
      • Access Permission: select "Public Read/Private Write".
    4. Click OK.
    5. Select Basic Configuration on the left of the bucket and click Add a Rule in "CORS (Cross-Origin Resource Sharing) Setting".
    6. In the "Add CORS Rule" pop-up window, add a rule.

    The main parameter information is as follows. Keep the remaining parameters as default:

    • Origin: enter *.
    • Allow-Methods: select "GET".
    • Expose-Headers: enter -.
      1. Click Submit.

    Modifying function configuration

    1. On the "Functions" page, click the function name to enter the "Function configuration" page.
    2. On the "Function configuration" page, click Edit in the top-right corner and configure the function as follows.
      • Execution Role: check "Enable" and select a permission policy containing COS data read/write permissions. SCF_QcsRole is selected here as an example.
        .
      • Environment Variable: add the following environment variables and configure them as.
        .
        keyvalue
        regionBucket region, which starts with `ap-` and ends with the region name.
        target_bucketName of the created bucket.
        target_pathDestination bucket path.
    3. Click Save.

    Generating invitation

    You can apply for an invitation in two ways:

    Method 1

    Run the following command on the command line.

    curl API gateway trigger URL  -d 'Name of the invited guest'

    The download address of the invitation can be obtained on the device, such as:

    curl https://service-xxxx.gz.apigw.tencentcs.com/release/test-123456 -d 'name'
    https://testxxxx.com//invitation-yun-ServerlessDays.jpg%

    Method 2

    1. Download the HTML page and change the URL to the URL of the API gateway trigger.

    2. Open the HTML page, enter the name of the invited guest to generate a poster, and access the URL to download it.

    Was this page helpful?

    Was this page helpful?

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