tencent cloud

Feedback

Implementing Custom Invitation with SCF + API Gateway

Last updated: 2022-07-21 11:35:50

    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 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 key parameters are as follows. Retain the default settings for other parameters.
    • Region: Select Guangzhou.
    • Name: Enter a custom name. This document uses test as an example.
    • Access Permission: Select Public Read/Private Write.
    1. Click Create.
    2. Select Security Management on the left of the bucket and click Add a Rule in CORS (Cross-Origin Resource Sharing) Setting.
    3. In the Add CORS Rule pop-up window, add a rule as shown below:

      The key parameters are as follows. Retain the default settings for other parameters.
    • Origin: Enter *.
    • Allow-Methods: Select GET.
    • Expose-Headers: Enter -.
    1. Click Save.

    Creating function and API Gateway trigger

    1. Log in to the SCF console and select Functions on the left sidebar.
    2. At the top of the Functions page, select Guangzhou region and click Create to enter the function creating page.
    3. Follow the procedure below to search for the custom invitation template as shown below. This document uses Python 2.7 as an example:
    • Creation method: Select Template.
    • Fuzzy search: Enter CustomInvitation and search.
      Click Learn more in the template to view relevant information in the Template details pop-up window, which can be downloaded.
    1. Click Next. The function name is automatically generated by default and can be modified as needed. Follow the prompts to enter the corresponding values of the environment variables required by the template in the Basic Configurations section and keep other parameters as default as shown below:

      Configure environment variables as shown below:
      keyvalue
      regionBucket region, which starts with `ap-` and ends with the region name. This document takes `ap-guangzhou` as an example.
      target_bucketName of the created bucket.
      target_pathPath of the destination bucket. To view the directory path of the bucket for storing invitations, 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.
      Note

      This example requires SCF to have the operation permissions of COS. Execution Role has been enabled by default, and an execution role has been automatically created and associated with the required COS permission policy QcloudCOSFullAccess. If you need to make adjustments, select Use the existing role or disable Execution Role.

    2. Click Complete.

    Generating invitation

    You can generate an invitation in two ways:

    Note

    You can get the access path of the API Gateway trigger on the Function Details > Trigger management page as shown below:

    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 as shown below:
    2. Open the HTML page, enter the name of the invited guest to generate a poster, and access the URL to download it.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support