tencent cloud

Feedback

Tencent Cloud's serverless application model

Last updated: 2022-03-18 16:32:55
This document is currently invalid. Please refer to the documentation page of the product.

    Introduction

    Tencent Cloud Serverless Application Model (TCSAM) is used to define serverless applications in Tencent Cloud.
    Serverless applications are triggered by events. A typical serverless application can have one or more SCF functions, which can be triggered by events such as uploading object files to COS And delivering messages to CMQ . These functions can run independently or use other resources such as COS and TencentDB. In addition, the most basic serverless application can have only one function.

    • Words such as "must", "must not", "required", "shall", "shall not", "should", "should not", "recommended", "may", and "optional" used in this document need to be interpreted based on RFC 2119 .
    • The TCSAM in this document is licensed under Apache License 2.0 , whose version is 2018Mui 11Mui 11

    Format and specifications

    TCSAM describes serverless applications using templates in YAML Or JSON Format.

    TCSAM Template

    All property names in TCSAM are Case-sensitive .

    Resources
    default:
      Type: TencentCloud::Serverless::Namespace
      hello_world:
        Type: TencentCloud::Serverless::Function
        
    

    properties
    CodeUri: ./
    Type: Event
    Description: This is a template function
    Handler: index.main_handler
    "MemorySize": 128,
    "Runtime": "Python2.7"
    "Timeout": 3,
    Events
    timer: ## Trigger name
    Type: Timer ## Timer trigger

       CronExpression: '*/5 * * * *'
    "Enabled": true

    Global Section

    It defines the global properties of a TCSAM template. Those properties will be inherited by TencentCloud::Serverless::Function And TencentCloud::Serverless::Api Resources。
    Sample:

    Globals:
    ## Function
      "Runtime": "Python2.7"
      "Timeout": 3,
      Handler: index.handler
      ## Environment
        "Variables": []
          DB_NAME: mydb
    


    Resource type

    TencentCloudServerlessNamespace

    SCF namespace is made up of a set of functions.

    TencentCloudServerlessFunction

    Describes a function under a certain namespace and the event source that triggers it.

    Properties

    Property Name Type Required DESCRIPTION
    Handler String Yes Entry execution method of a function.
    Runtime String Yes Operating environment of a function. Value range: Python2.7, Python3.6, Nodejs6.10, Nodejs8.9, PHP5, PHP7, Golang1, Java8.
    CodeUri String Yes Code location, which supports various forms such as local file, local directory, local .zip package, COS bucket, and object. For more information, see CodeUri .
    DESCRIPTION String Port: 789 Function description.
    MemorySize Integer Port: 789 Memory size allocated during function execution. Unit: MB, Default value: 128, increase incrementally by 128 MB
    TimeOut Integer Port: 789 Maximum execution duration of a function before it is terminated. Unit: Seconds. Default value: 3.
    Role String Port: 789 Specifies an execution role for a function by entering the role name. If this field is left blank, the QCS_SCFExcuteRole Role will be created for the function by default.
    Environment Environment variable object Port: 789 Configures the Environment Variable For a function.
    Events Event source object Port: 789 Defines the event source that triggers a function.
    VpcConfig VPC configuration object Port: 789 Configures the VPC access for a function.

    Examples: TencentCloudServerlessNamespace and TencentCloudServerlessFunction

    ProjectTest: # Namespace name
    Type: 'TencentCloud::Serverless::Namespace'
    TestFunction: # Function name
      Type: 'TencentCloud::Serverless::Function'
      
    

    properties
    Handler: index.handler
    "Runtime": "Python2.7"
    CodeUri: './'
    Description: Cron function
    Role: QCS_SCFExcuteRole
    "Timeout": 3,
    "MemorySize": 128,

    <span id = "event-source-type"></span>
    > If there are multiple functions, a `template.yaml` File can be created outside the function directory, and each function's CodeUri can be specified in the file, so multiple functions will be deployed at the same time.
    > 
    > - The VS Code plug-in does not support the deployment of multiple functions at the same time. Please deploy a single function in turn.
    As shown below, "func1" and "func2" will be deployed automatically.
    

    yaml
    Globals:

    Function

    "Timeout": 3,
    "MemorySize": 128,
    "Runtime": "Python2.7"
    

    Resources
    default:
    Type: TencentCloud::Serverless::Namespace
    func1:
    Type: TencentCloud::Serverless::Function

     CodeUri: ./func1
    Description: This is a template function
    Handler: index.main_handler
    func2:
    Type: TencentCloud::Serverless::Function

    properties
    CodeUri: ./func2
    Description: This is a template function
    Handler: index.main_handler

    ## Event source type
    - [Timer](#timer)
    - [COS](#cos)
    - [API](#api)
    - [CMQ](#cmq)
    - [CKafka](#ckafka)
    ### Timer
    Describes an object whose type is [Timer Trigger](https://intl.cloud.tencent.com/document/product/583/9708) .
    #### Properties
    |Property Name|Type|Required|DESCRIPTION|
    |-|-|-|-|
    |CronExpression| `String` |Yes|Time when a function is triggered, which supports specifying a [Cron Expression](https://intl.cloud.tencent.com/document/product/583/9708) .|
    |Message| `String` |No|Custom trigger additional messages, which can be entered into the cloud function. `event` Get in the.|
    |Enable| `Boolean` |Port: 789|Whether to enable a trigger.|
    #### Example: Timer event source object
    

    yaml
    Events
    timername:
    &Type=timer

     CronExpression: '*/5 * * * *'
    Message:"It's an additional message."
    "Enabled": true

    COS

    Describes an object whose type is COS Trigger .

    Properties

    Property Name Type Required DESCRIPTION
    Bucket String Yes COS bucket name.
    Events String Yes Event that triggers a function. Value range: cos:ObjectCreated:* , cos:ObjectCreated:Put , cos:ObjectCreated:Post , cos:ObjectCreated:Copy , cos:ObjectCreated:Append , cos:ObjectCreated:CompleteMultipartUpload , cos:ObjectRemove:* , cos:ObjectRemove:Delete , cos:ObjectRemove:DeleteMarkerCreated .
    Filter COS Notification Filter Port: 789 Filter rule of a trigger event.
    Enable Boolean Port: 789 Whether to enable a trigger.

    Example: COS event source object

    Events
    cli-appid.cos.ap-beijing.myqcloud.com: # full bucket name
         "Type": "cos",
         
    

    properties
    Bucket: cli-appid.cos.ap-beijing.myqcloud.com
    * filter
    Prefix: filterdir/
    Suffix: .jpg
    Events: cos:ObjectCreated:*
    "Enabled": true

    Bucket name and value of the `bucket` Field can be viewed in [COS Console](https://console.intl.cloud.tencent.com/cos/bucket) , as shown below:
    <span id="tencentcloudserverlessapi"></span>
    API Gateway 
    Describes an object whose type is [API Gateway Trigger](https://intl.cloud.tencent.com/document/product/583/12513?from_cn_redirect=1) .
    > If an API resource object and an event source object of API gateway trigger exist in the description file, the former will take effect.
    #### Properties
    |Property Name|Type|Required|DESCRIPTION|
    |-|-|-|-|
    |StageName| `String` |Port: 789|Name of the release stage. An API gateway is used as the first path segment of the called uniform resource identifier (URI). Value range: `test` , `prepub` , `release` . Default value: `release` When serving new APIs, `test` When serving existing APIs.|
    |HttpMethod| `String` |Port: 789|HTTP request method. Value range: `ANY` , `GET` , `POST` , `PUT` , `DELETE` , `HEAD` . Default value: `ANY` .|
    |IntegratedResponse| `Boolean` |Port: 789|Whether to enable integrated response. Default value: `false` .|
    |Enable| `Boolean` |Port: 789|Whether to enable a trigger.|
    |ServiceId| `String` |Port: 789|Gateway service ID. If `ServiceId` Is not entered in `template.yaml` During plugin deployment via SCF CLI or VS Code, the system will create a new gateway and return the relevant information. You can enter the `ServiceId` In this information into the `template.yaml` File, so that gateways will not be created repeatedly during future deployments.|
    #### Example: API event source object
    

    yaml
    Events
    hello_world_apigw: # ${FunctionName} + '_apigw'
    Type: APIGW

     StageName: release
    ServiceId
    HttpMethod: ANY

    "CMQ": {
    Describes an object whose type is CMQ Trigger .

    Properties

    Property Name Type Required DESCRIPTION
    Name String Yes Message queue name.
    Enable Boolean Port: 789 Whether to enable a trigger.

    Example: CMQ event source object

    Events
    "TopicName": "topic name",
         Type: CMQ
         
    

    properties
    Name: qname

    The value of the `Name` Field is the topic name, which can be obtained in [CMQ Console](https://console.intl.cloud.tencent.com/cmq/topic?rid=1) , as shown below:
    "Ckafka": {
    Describes an object whose type is [CKafka Trigger](https://intl.cloud.tencent.com/document/product/583/17530) .
    #### Properties
    |Property Name|Type|Required|DESCRIPTION|
    |-|-|-|-|
    |Name| `String` |Yes|CKafka ID.|
    |Topic| `String` |Yes|CKafka topic name.|
    |MaxMsgNum| `Integer` |Yes|Maximum number of messages. Value range: 1Mel 1000.|
    |Offset| `String` |Yes|Start offset position. Default value: `latest` .|
    |Enable| `Boolean` |Port: 789|Whether to enable a trigger.|
    #### Example: CKafka event source object
    

    yaml
    Events
    "name/ckafka:*",
    Type: Ckafka

    Name: ckafka-XXXXX
    Topic: test_scf
    MaxMsgNum: 999
    Offset: latest
    "Enabled": true

    The value of the Name Field is CKafka ID, and the value of the Topic Field is the topic name, which can be obtained in the CKafka Console , as shown below:

    Property Type

    Event source object

    Describes an object of the event source that triggers a function.

    Properties

    Property Name Type Required DESCRIPTION
    Type String Yes Event type. Value range: Timer , COS , API , CMQ . For more information on all types, see Event source type .
    Properties * Yes Describes the object of the event's mapping property, which must comply with the defined Type . For more information on all types, see Event source type .

    Example: Event source object

    Events
    &Type=timer
    

    properties
    CronExpression: '*/5 * * * *'
    Message:"It's an additional message."
    "Enabled": true

    <span id="VPCconfigurationObject"></span>
    ### VPC configuration object
    The properties of a VPC configuration object include `VpcId` And `SubnetId` . For more information, see [VPC configuration object](https://intl.cloud.tencent.com/document/api/583/17244?from_cn_redirect=1#VpcConfig) .
    |Property Name|Type|Required|DESCRIPTION|
    |-|-|-|-|
    |vpcId| `String` |Yes|VPC ID.|
    |SubnetId|Yes|String|VPC subnet ID|
    #### Example: VPC configuration object
    

    VpcConfig

    VpcId: 'vpc-qdqc5k2p'
    "SubnetId": "subnet-6d7kj98i",

    <span id="Environmentvariableobject"></span>
    ### Environment variable object
    An environment variable object describes the environment variable property that can be configured by a function. The environment variable configuration is a series of key-value pairs.
    |Property Name|Type|DESCRIPTION|
    |-|-|-|
    |Variables|Mapping from `String` To `String` |Defines string-to-string mapping of the environment variable, where the variable name is `key` And the value is `value` . The variable name is a combination of letters and digits that begins with a letter. The variable value is a combination of letters, digits, and special characters `_(){}[]$*+-\/"#',;.@!?` .|
    #### Example: Environment variable object
    

    Environment

    "Variables": []
    MYSQL_USER: root
    MYSQL_PASS: pass

    <span id="typeOfData"></span>
    ## Data types
    - [COS object](#cos-object)
    - [Code URI object](#codeuri-object)
    - [COS notification filter](#cos-filter)
    <span id = "cos-object"></span>
    ### COS Object
    By setting `Bucket` And `Key` , a COS location can be specified to indicate the code storage location. 
    Sample:
    

    yaml
    CodeUri:
    Bucket: mycodebucket
    Key: '/code.zip'

    <span id = "codeuri-object"></span>
    ### CodeUri<span id = "codeuri-object1"></span>
    CodeUri is used to specify the code storage location, which can be a file, folder, or .zip package in the local file system. 
    Sample:
    

    yaml
    CodeUri: index.py

    
    

    yaml
    CodeUri: ./build

    
    

    yaml
    CodeUri: /user/code/func/build.zip

    <span id = "cos-filter"></span>
    ### COS notification filter
    Specifies the filter configuration during COS notifications. It combines a prefix ignore query string and a suffix ignore query string. 
    Sample:
    

    yaml

    • filter
      Prefix: 'filterdir/'
      Suffix: '.jpg'
      
      
    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