Custom Invitation

Last updated: 2020-12-31 14:18:09


    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.


    Creating function

    1. Log in to the SCF Console and select Function Service 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".
      • Creation 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.
    3. 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 as shown below:

      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 Security Management 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 -.
    7. 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 as shown below:
      • Environment Variable: add the following environment variables and configure them as shown below:
        regionBucket region, which starts with `ap-` and ends with the region name.
        target_bucketName of the created bucket.
        target_pathPath of the destination bucket. To view the directory path of the bucket for storing invitations, please go to **Bucket List** and **enter the corresponding bucket**. For example, if the directory is `example`, the destination path here is `/example`. If there is no directory created in the bucket, enter "/" here.
    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 -d 'name'

    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