ALIYUN::FC::Trigger is used to trigger the execution of a function.

In an event-driven computing model, the source is the event producer, the function is the event processor, and the trigger manages different sources in a centralized manner. On the event source side, when an event matching the rules defined by a trigger occurs, the event source invokes the corresponding function.

Syntax

{
  "Type": "ALIYUN::FC::Trigger",
  "Properties": {
    "TriggerConfig": Map,
    "InvocationRole": String,
    "FunctionName": String,
    "ServiceName": String,
    "TriggerName": String,
    "TriggerType": String,
    "Qualifier": String,
    "SourceArn": String
  }
}

Properties

Property Type Required Editable Description Constraint
ServiceName String Yes No The name of the service to which the function belongs. The name must be 1 to 128 characters in length.
FunctionName String Yes No The name of the function for which you want to create a trigger. None
TriggerName String Yes No The name of the trigger. The name must be 1 to 128 characters in length and can contain digits, letters, hyphens (-), and underscores (_). It must start with a letter or underscore (_).
TriggerType String Yes No The type of the trigger. Valid values: oss, log, tablestore, timer, mns_topic, cdn_events, and http. Note: You can create an HTTP trigger only when you create a function. When an HTTP trigger is configured for a function, you cannot create other types of triggers for the function.
TriggerConfig Map Yes Yes The trigger configurations. The configurations vary with the trigger type.
InvocationRole String No Yes The role used to grant an event source the permissions to invoke the function on behalf of users. Example: "acs:ram::1234567890:role/fc-test". The parameter is optional when TriggerType is set to timer or http. The parameter is required when TriggerType is set to a value other than timer and http.
SourceArn String No No The Alibaba Cloud Resource Name (ARN) of the event source. Example: "acs:<The name of the Alibaba Cloud service>:<The region>:<The ID of the Alibaba Cloud account>:<Suffix>". Suffix formats for different types of triggers are listed as follows:
  • oss: <BucketName>
  • log: <ProjectName>/<LogStoreName>
  • ots: instance/<OTSInstanceName>/table/<TableName>
  • mns: /topics/<TopicName>
The parameter is optional when TriggerType is set to timer or http. The parameter is required when TriggerType is set to a value other than timer and http.
Qualifier String No Yes The version of the trigger. Default value: LATEST.

oss-TriggerConfig syntax

"TriggerConfig": {
  "BucketName": String,
  "Events": List,
  "Filter": Map
}      

oss-TriggerConfig properties

Property Type Required Editable Description Constraint
BucketName String Yes No The name of the bucket. You must select an OSS bucket as the event source. The buckets in the same region are displayed in the Bucket drop-down list.
Events String Yes Yes The triggering event that indicates the operations you performed on Alibaba Cloud resources. Example: oss:ObjectCreated:*. None
Filter Map No Yes The trigger rules to avoid cyclic triggering. Example:
"Filter": {
  "Key": {
    "Prefix": "prefix",
    "Suffix": "suffix"
  }
}
The values of Prefix and Suffix must be custom strings.

log-TriggerConfig syntax

"TriggerConfig": {
  "SourceConfig": Map,
  "LogConfig": Map,
  "JobConfig": Map,
  "FunctionParameter": Map,
  "Enable": Boolean
}

log-TriggerConfig properties

Property Type Required Editable Description Constraint
SourceConfig Map Yes No The Logstore configurations. Example: {"LogStore": "<SLS_LogStore>"}. None
LogConfig Map Yes Yes The configurations of the Log Service project and the Logstore for the trigger. Example: {"Project": "<SLS_Project>", "LogStore": "SLS_LogStore"}. The Log Service project is required and cannot be changed. The log file for the trigger is optional and can be changed. The log file cannot be the same as the Logstore set in SourceConfig.
JobConfig Map Yes Yes The task configurations. This parameter is used to set the maximum allowable number of retries and the trigger interval. Example: {"MaxRetryTime": 3, "TriggerInterval": 60}.

The trigger interval is measured in seconds.

The maximum allowable number of retries ranges from 0 to 100.

FunctionParameter Map Yes Yes The function configurations used to pass parameters to the function. If no parameters are specified, enter braces {}.
Enable Boolean Yes Yes Specifies whether to enable the trigger. Valid values: true and false.

timer-TriggerConfig syntax

"TriggerConfig": {
  "Payload": String,
  "CronExpression": String,
  "Enabled": Boolean
}

timer-TriggerConfig properties

Property Type Required Editable Description Constraint
Payload String No Yes The event that is triggered. None
CronExpression String Yes Yes The cron expression used to set the triggering time. The cron expression uses Coordinated Universal Time (UTC).
Enabled Boolean Yes Yes Specifies whether to enable the trigger. Valid values: true and false.

tablestore-TriggerConfig syntax

"TriggerConfig",: {
  "InstanceName": String,
  "TableName": String
}

tablestore-TriggerConfig properties

Property Type Required Editable Description Constraint
InstanceName String Yes No The name of the Tablestore instance. None
TableName String Yes No The name of the table. None

mns_topic-TriggerConfig syntax

"TriggerConfig": {
  "NotifyStrategy": String,
  "NotifyContentFormat": String,
  "FilterTag": String
}

mns_topic-TriggerConfig properties

Property Type Required Editable Description Constraint
NotifyStrategy String Yes No The retry policy. For more information, see NotifyStrategy. Valid values:
  • BACKOFF_RETRY
  • EXPONENTIAL_DECAY_RETRY
NotifyContentFormat String Yes No The format of the event. Valid values: STREAM and JSON.
FilterTag String No No The filtering tag. None

Response parameters

Fn::GetAtt

  • TriggerId: the unique ID generated by the system for each trigger.
  • ServiceName: the name of the service to which the function belongs.
  • FunctionName: the name of the function.
  • TriggerName: the name of the trigger.

Examples

JSON format

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "ServiceName": {
      "Type": "String",
      "Description": "FC ServiceName",
      "Default": "ros-test"
    },
    "FunctionName": {
      "Type": "String",
      "Description": "Function Name",
      "Default": "PythonFunc"
    },
    "SourceCode": {
      "Type": "String",
      "Description": "Function SourceCode",
      "Default": "def handler(event, context):\n\treturn 'Hello World!'"
    },
    "Handler": {
      "Type": "String",
      "Description": "Handler",
      "Default": "index.handler"
    },
    "Runtime": {
      "Type": "String",
      "Description": "Runtime",
      "Default": "python3"
    },
    "TriggerName": {
      "Type": "String",
      "Default": "test-trigger"
    },
    "TriggerType": {
      "Type": "String",
      "Default": "timer"
    },
    "CronExpression": {
      "Type": "String",
      "Default": "0 0/5 * * * *"
    },
    "Enabled": {
      "Type": "Boolean",
      "Default": "true"
    }
  },
  "Resources": {
    "Service": {
      "Type": "ALIYUN::FC::Service",
      "Properties": {
        "ServiceName": {
          "Ref": "ServiceName"
        }
      }
    },
    "Function": {
      "DependsOn": "Service",
      "Type": "ALIYUN::FC::Function",
      "Properties": {
        "ServiceName": {
          "Ref": "ServiceName"
        },
        "Code": {
          "SourceCode": {
            "Ref": "SourceCode"
          }
        },
        "Handler": {
          "Ref": "Handler"
        },
        "Runtime": {
          "Ref": "Runtime"
        },
        "FunctionName": {
          "Ref": "FunctionName"
        }
      }
    },
    "Trigger": {
      "DependsOn": "Function",
      "Type": "ALIYUN::FC::Trigger",
      "Properties": {
        "ServiceName": {
          "Ref": "ServiceName"
        },
        "FunctionName": {
          "Ref": "FunctionName"
        },
        "TriggerName": {
          "Ref": "TriggerName"
        },
        "TriggerType": {
          "Ref": "TriggerType"
        },
        "TriggerConfig": {
          "CronExpression": {
            "Ref": "CronExpression"
          },
          "Enabled": {
            "Ref": "Enabled"
          }
        }
      }
    }
  },
  "Outputs": {
    "TriggerId": {
      "Value": {
        "Fn::GetAtt": [
          "Trigger",
          "TriggerId"
        ]
      }
    }
  }
}

YAML format

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ServiceName:
    Type: String
    Description: FC ServiceName
    Default: ros-test
  FunctionName:
    Type: String
    Description: Function Name
    Default: PythonFunc
  SourceCode:
    Type: String
    Description: Function SourceCode
    Default: "def handler(event, context):\n\treturn 'Hello World!'"
  Handler:
    Type: String
    Description: Handler
    Default: index.handler
  Runtime:
    Type: String
    Description: Runtime
    Default: python3
  TriggerName:
    Type: String
    Default: test-trigger
  TriggerType:
    Type: String
    Default: timer
  CronExpression:
    Type: String
    Default: 0 0/5 * * * *
  Enabled:
    Type: Boolean
    Default: 'true'
Resources:
  Service:
    Type: 'ALIYUN::FC::Service'
    Properties:
      ServiceName:
        Ref: ServiceName
  Function:
    DependsOn: Service
    Type: 'ALIYUN::FC::Function'
    Properties:
      ServiceName:
        Ref: ServiceName
      Code:
        SourceCode:
          Ref: SourceCode
      Handler:
        Ref: Handler
      Runtime:
        Ref: Runtime
      FunctionName:
        Ref: FunctionName
  Trigger:
    DependsOn: Function
    Type: 'ALIYUN::FC::Trigger'
    Properties:
      ServiceName:
        Ref: ServiceName
      FunctionName:
        Ref: FunctionName
      TriggerName:
        Ref: TriggerName
      TriggerType:
        Ref: TriggerType
      TriggerConfig:
        CronExpression:
          Ref: CronExpression
        Enabled:
          Ref: Enabled
Outputs:
  TriggerId:
    Value:
      'Fn::GetAtt':
        - Trigger
        - TriggerId