Tous les produits
Search
Centre de documentation

Resource Orchestration Service:ALIYUN::FC::Trigger

Dernière mise à jour :Aug 10, 2026

La ressource ALIYUN::FC::Trigger permet de déclencher l'exécution d'une fonction.

Dans un modèle de calcul événementiel, les sources d'événements génèrent des événements que les fonctions traitent. Les triggers (déclencheurs) assurent une gestion centralisée des différentes sources d'événements. Lorsqu'un événement correspondant aux règles définies par un trigger se produit, la source d'événement appelle la fonction concernée.

Syntaxe

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

Propriétés

Propriété

Type

Obligatoire

Modifiable

Description

Contrainte

ServiceName

String

Oui

Non

Le nom du service auquel appartient la fonction.

Le nom doit comporter entre 1 et 128 caractères.

FunctionName

String

Oui

Non

Le nom de la fonction pour laquelle vous souhaitez créer un trigger.

Aucune.

TriggerName

String

Oui

Non

Le nom du trigger.

Le nom doit comporter entre 1 et 128 caractères et peut contenir des chiffres, des lettres, des traits d'union (-) et des underscores (_). Il doit commencer par une lettre ou un underscore (_).

TriggerType

String

Oui

Non

Le type de trigger.

Valeurs valides :

  • oss : trigger Object Storage Service (OSS)

  • log : trigger Log Service

  • tablestore : trigger Tablestore

  • timer : trigger temporel

  • mns_topic : trigger de topic Message Service (MNS)

  • cdn_events : trigger d'événement Alibaba Cloud CDN (CDN)

  • http : trigger HTTP

    Remarque

    Vous ne pouvez créer un trigger HTTP qu'au moment de la création d'une fonction. Lorsqu'un trigger HTTP est configuré pour une fonction, vous ne pouvez pas créer d'autres types de triggers pour cette fonction.

TriggerConfig

Map

Oui

Oui

Les configurations du trigger.

Les configurations varient selon le type de trigger.

InvocationRole

String

Non

Oui

Le rôle de trigger utilisé pour accorder à une source d'événement les autorisations nécessaires afin d'appeler la fonction en votre nom. Exemple : acs:ram::164696547407****:role/fc-test.

Cette propriété est facultative lorsque TriggerType est défini sur timer ou http. Elle est obligatoire lorsque TriggerType est défini sur une valeur autre que timer et http.

La section suivante répertorie les entités de confiance et les politiques d'autorisation de rôle pour les différents types de triggers :

  • oss

    • Entité de confiance : oss.aliyuncs.com

    • Action dans la politique : fc:InvokeFunction

  • log

    • Entité de confiance : log.aliyuncs.com

    • Action dans la politique : log:PostLogStoreLogs

  • tablestore

    • Entité de confiance : 1604337383174****

    • Action dans la politique : fc:InvokeFunction, ots:BatchGet, ots:Describe, ots:Get et ots:List

  • mns_topic

    • Entité de confiance : mns.aliyuncs.com

    • Action dans la politique : dm:BatchSendMail, dm:SingleSendMail et dm:Query

  • cdn_events

    • Entité de confiance : cdn.aliyuncs.com

    • Action dans la politique : fc:InvokeFunction

SourceArn

String

Non

Non

L'Alibaba Cloud Resource Name (ARN) de la source d'événement.

Cette propriété est facultative lorsque TriggerType est défini sur timer ou http. Elle est obligatoire lorsque TriggerType est défini sur une valeur autre que timer et http.

La section suivante répertorie les formats et exemples d'ARN de source d'événement pour les différents types de triggers :

  • oss

    • Format : acs:oss:<RegionId>:<TenantId>:<OssBucketName>

    • Exemple : acs:oss:cn-hangzhou:164696547407****:test-trigger-bucket

  • log

    • Format : acs:log:<RegionId>:<TenantId>:project/<Value of Project in LogConfig>

    • Exemple : acs:log:cn-hangzhou:164696547407****:project/logtrigger

  • tablestore

    • Format : acs:ots:<RegionId>:<TenantId>:instance/<OtsInstance>/table/<OtsTable>

    • Exemple : acs:ots:cn-hangzhou:164696547407****:instance/otstrigger/table/tb

  • mns_topic

    • Format : acs:mns:<RegionId>:<TenantId>:/topics/<MnsTopic>

    • Exemple : acs:mns:cn-hangzhou:164696547407****:/topics/triggertopic

  • cdn_events

    • Format : acs:cdn:*:<TenantId>

    • Exemple : acs:cdn:*:164696547407****

Remarque

Remplacez TenantId par l'ID de votre compte Alibaba Cloud.

Qualifier

String

Non

Oui

La version du trigger.

Valeur par défaut : LATEST.

Syntaxe oss-TriggerConfig

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

Propriétés oss-TriggerConfig

Propriété

Type

Obligatoire

Modifiable

Description

Contrainte

BucketName

String

Oui

Non

Le nom du bucket.

Vous devez sélectionner un bucket OSS comme source d'événement. Les buckets de la même région sont affichés dans la liste déroulante Bucket.

Events

String

Oui

Oui

Les événements de trigger, qui représentent les opérations effectuées sur les ressources Alibaba Cloud.

Exemple : oss:ObjectCreated:*.

Filter

Map

Non

Oui

La règle de trigger, utilisée pour éviter les déclenchements cycliques.

Les valeurs de Prefix et Suffix doivent être des chaînes personnalisées.

Exemple :

"Filter": {
  "Key": {
    "Prefix": "prefix",
    "Suffix": "suffix"
  }
}

Syntaxe log-TriggerConfig

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

Propriétés log-TriggerConfig

Propriété

Type

Obligatoire

Modifiable

Description

Contrainte

SourceConfig

Map

Oui

Non

Les configurations du Logstore.

Exemple : {"LogStore": "<SLS_LogStore>"}.

LogConfig

Map

Oui

Oui

Les configurations du projet Log Service et du Logstore pour le trigger.

Project : le projet Log Service. Cette propriété est obligatoire mais non modifiable. LogStore : le Logstore pour le trigger. Cette propriété est facultative et modifiable. Le Logstore ne peut pas être identique à la valeur de LogStore dans la propriété SourceConfig.

Exemple : {"Project": "<SLS_Project>", "LogStore": "SLS_LogStore"}.

JobConfig

Map

Oui

Oui

Les configurations de déclenchement, qui spécifient le nombre maximal de tentatives et l'intervalle de déclenchement.

MaxRetryTime : l'intervalle de déclenchement. Unité : secondes.

TriggerInterval : le nombre maximal de tentatives. Valeurs valides : 0 à 100.

Exemple : {"MaxRetryTime": 3, "TriggerInterval": 60}.

FunctionParameter

Map

Oui

Oui

Les configurations de fonction utilisées pour transmettre des paramètres à la fonction.

Si vous ne souhaitez pas transmettre de paramètres, définissez la valeur sur des accolades ({ }).

Enable

Boolean

Oui

Oui

Indique si le trigger est activé.

Valeurs valides :

  • true

  • false

Syntaxe timer-TriggerConfig

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

Propriétés timer-TriggerConfig

Propriété

Type

Obligatoire

Modifiable

Description

Contrainte

Payload

String

Non

Oui

Le message du trigger.

Aucune.

CronExpression

String

Oui

Oui

L'expression CRON utilisée pour spécifier l'heure de déclenchement.

L'expression CRON utilise le temps universel coordonné (UTC).

Enabled

Boolean

Oui

Oui

Indique si le trigger est activé.

Valeurs valides :

  • true

  • false

Syntaxe tablestore-TriggerConfig

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

Propriétés tablestore-TriggerConfig

Propriété

Type

Obligatoire

Modifiable

Description

Contrainte

InstanceName

String

Oui

Non

Le nom de l'instance Tablestore.

Aucune.

TableName

String

Oui

Non

Le nom de la table de données.

Aucune.

Syntaxe mns_topic-TriggerConfig

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

Propriétés mns_topic-TriggerConfig

Propriété

Type

Obligatoire

Modifiable

Description

Contrainte

NotifyStrategy

String

Oui

Non

La stratégie de nouvelle tentative.

Valeurs valides :

  • BACKOFF_RETRY

  • EXPONENTIAL_DECAY_RETRY

Pour plus d'informations, consultez NotifyStrategy.

NotifyContentFormat

String

Oui

Non

Le format de l'événement.

Valeurs valides :

  • STREAM

  • JSON

FilterTag

String

Non

Non

Le tag de filtrage.

Aucune.

Syntaxe cdn-TriggerConfig

"TriggerConfig": {
  "EventName": String,
  "EventVersion": String,
  "Notes": String,
  "Filter": List
}

Propriétés cdn-TriggerConfig

Propriété

Type

Obligatoire

Modifiable

Description

Contrainte

EventName

String

Oui

Non

L'événement de trigger.

Valeurs valides :

  • CachedObjectsBlocked

  • CachedObjectsPushed

  • CachedObjectsRefreshed

  • LogFileCreated

  • CdnDomainStarted

  • CdnDomainStopped

  • CdnDomainAdded

  • CdnDomainDeleted

EventVersion

String

Oui

Non

La version de l'événement de trigger.

Aucune.

Notes

String

Oui

Oui

Les remarques.

Aucune.

Filter

List

Oui

Oui

Les filtres.

La clé de chaque filtre est Domain. Vous devez spécifier au moins un filtre. Exemple : [{"Domain": "example.com"}, {"Domain": "example.org"}, ...].

Syntaxe http-TriggerConfig

Remarque

Vous ne pouvez créer un trigger HTTP qu'au moment de la création d'une fonction. Lorsqu'un trigger HTTP est configuré pour une fonction, vous ne pouvez pas créer d'autres types de triggers pour cette fonction.

"TriggerConfig": {
  "AuthType": String,
  "Methods": List
}

Propriétés http-TriggerConfig

Propriété

Type

Obligatoire

Modifiable

Description

Contrainte

AuthType

String

Oui

Non

La méthode d'authentification.

Valeurs valides :

  • anonymous

  • function

Methods

List

Oui

Non

Les méthodes de requête.

Valeurs valides :

  • GET

  • POST

  • PUT

  • DELETE

  • HEAD

  • PATCH

Exemples : ["GET"] et ["POST", "PUT"].

Valeurs de retour

Fn::GetAtt

  • TriggerId : l'ID unique généré par le système pour chaque trigger.

  • ServiceName : le nom du service auquel appartient la fonction.

  • FunctionName : le nom de la fonction.

  • TriggerName : le nom du trigger.

  • UrlInternet : l'adresse de domaine public.

  • UrlIntranet : l'adresse de domaine privé.

Exemples

  • YAML format

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      ServiceName:
        Type: String
      FunctionName:
        Type: String
      CdnDomain:
        Type: Json
      SourceConfigLogStore:
        Type: String
      LogConfig:
        Type: Json
        Description: 'for example: {"Project": "testviper", "LogStore": "vipertest"}'
      MnsTopic:
        Type: String
      OssBucketName:
        Type: String
      OtsInstance:
        Type: String
      OtsTable:
        Type: String
      OtsInvocationRoleArn:
        Type: String
    Resources:
      Service:
        Type: 'ALIYUN::FC::Service'
        Properties:
          ServiceName:
            Ref: ServiceName
      Function:
        DependsOn: Service
        Type: 'ALIYUN::FC::Function'
        Properties:
          ServiceName:
            Ref: ServiceName
          Code:
            SourceCode: "def handler(event, context):\n\treturn 'Hello World!'"
          Handler: index.handler
          Runtime: python3
          FunctionName:
            Ref: FunctionName
      Role:
        Type: 'ALIYUN::RAM::Role'
        Properties:
          AssumeRolePolicyDocument:
            Version: 1
            Statement:
              - Action: 'sts:AssumeRole'
                Effect: Allow
                Principal:
                  Service:
                    - cdn.aliyuncs.com
                    - fc.aliyuncs.com
                    - mns.aliyuncs.com
                    - log.aliyuncs.com
                    - oss.aliyuncs.com
          Policies:
            - PolicyName: FcTrigger
              PolicyDocument:
                Version: '1'
                Statement:
                  - Effect: Allow
                    Action:
                      - 'fc:InvokeFunction'
                      - 'log:PostLogStoreLogs'
                      - 'dm:*'
                      - 'dm:BatchSendMail'
                      - 'dm:SingleSendMail'
                      - 'dm:Query*'
                    Resource:
                      - '*'
          RoleName: Trigger
      CdnTrigger:
        DependsOn: Function
        Type: 'ALIYUN::FC::Trigger'
        Properties:
          ServiceName:
            Ref: ServiceName
          FunctionName:
            Ref: FunctionName
          TriggerName: cdn
          TriggerType: cdn_events
          SourceArn:
            'Fn::Sub': 'acs:cdn:*:${ALIYUN::TenantId}'
          InvocationRole:
            'Fn::GetAtt':
              - Role
              - Arn
          TriggerConfig:
            EventName: CachedObjectsBlocked
            EventVersion: 1.0.0
            Notes: test
            Filter:
              Domain:
                Ref: CdnDomain
      LogTrigger:
        DependsOn: Function
        Type: 'ALIYUN::FC::Trigger'
        Properties:
          ServiceName:
            Ref: ServiceName
          FunctionName:
            Ref: FunctionName
          TriggerName: log
          TriggerType: log
          SourceArn:
            'Fn::Join':
              - ''
              - - 'Fn::Sub': 'acs:log:${ALIYUN::Region}:${ALIYUN::TenantId}:project/'
                - 'Fn::Select':
                    - Project
                    - Ref: LogConfig
          InvocationRole:
            'Fn::GetAtt':
              - Role
              - Arn
          TriggerConfig:
            SourceConfig:
              LogStore:
                Ref: SourceConfigLogStore
            LogConfig:
              Ref: LogConfig
            JobConfig:
              MaxRetryTime: 3
              TriggerInterval: 60
            FunctionParameter: {}
            Enable: false
      MnsTrigger:
        DependsOn: Function
        Type: 'ALIYUN::FC::Trigger'
        Properties:
          ServiceName:
            Ref: ServiceName
          FunctionName:
            Ref: FunctionName
          TriggerName: mns
          TriggerType: mns_topic
          SourceArn:
            'Fn::Sub': 'acs:mns:${ALIYUN::Region}:${ALIYUN::TenantId}:/topics/${MnsTopic}'
          InvocationRole:
            'Fn::GetAtt':
              - Role
              - Arn
          TriggerConfig:
            NotifyStrategy: BACKOFF_RETRY
            NotifyContentFormat: STREAM
            FilterTag: test
      OssTrigger:
        DependsOn: Function
        Type: 'ALIYUN::FC::Trigger'
        Properties:
          ServiceName:
            Ref: ServiceName
          FunctionName:
            Ref: FunctionName
          TriggerName: oss
          TriggerType: oss
          SourceArn:
            'Fn::Sub': 'acs:oss:${ALIYUN::Region}:${ALIYUN::TenantId}:${OssBucketName}'
          InvocationRole:
            'Fn::GetAtt':
              - Role
              - Arn
          TriggerConfig:
            BucketName:
              Ref: OssBucketName
            Events:
              - 'oss:ObjectCreated:*'
            Filter:
              Key:
                Prefix: b
                Suffix: a
      OtsTrigger:
        DependsOn: Function
        Type: 'ALIYUN::FC::Trigger'
        Properties:
          ServiceName:
            Ref: ServiceName
          FunctionName:
            Ref: FunctionName
          TriggerName: ots
          TriggerType: tablestore
          SourceArn:
            'Fn::Sub': >-
              acs:ots:${ALIYUN::Region}:${ALIYUN::TenantId}:instance/${OtsInstance}/table/${OtsTable}
          InvocationRole:
            Ref: OtsInvocationRoleArn
          TriggerConfig:
            InstanceName:
              Ref: OtsInstance
            TableName:
              Ref: OtsTable
      TimerTrigger:
        DependsOn: Function
        Type: 'ALIYUN::FC::Trigger'
        Properties:
          ServiceName:
            Ref: ServiceName
          FunctionName:
            Ref: FunctionName
          TriggerName: timer
          TriggerType: timer
          TriggerConfig:
            CronExpression: 0 0/5 * * * *
            Enabled: true
  • JSON format

    {
      "ROSTemplateFormatVersion": "2015-09-01",
      "Parameters": {
        "ServiceName": {
          "Type": "String"
        },
        "FunctionName": {
          "Type": "String"
        },
        "CdnDomain": {
          "Type": "Json"
        },
        "SourceConfigLogStore": {
          "Type": "String"
        },
        "LogConfig": {
          "Type": "Json",
          "Description": "for example: {\"Project\": \"testviper\", \"LogStore\": \"vipertest\"}"
        },
        "MnsTopic": {
          "Type": "String"
        },
        "OssBucketName": {
          "Type": "String"
        },
        "OtsInstance": {
          "Type": "String"
        },
        "OtsTable": {
          "Type": "String"
        },
        "OtsInvocationRoleArn": {
          "Type": "String"
        }
      },
      "Resources": {
        "Service": {
          "Type": "ALIYUN::FC::Service",
          "Properties": {
            "ServiceName": {
              "Ref": "ServiceName"
            }
          }
        },
        "Function": {
          "DependsOn": "Service",
          "Type": "ALIYUN::FC::Function",
          "Properties": {
            "ServiceName": {
              "Ref": "ServiceName"
            },
            "Code": {
              "SourceCode": "def handler(event, context):\n\treturn 'Hello World!'"
            },
            "Handler": "index.handler",
            "Runtime": "python3",
            "FunctionName": {
              "Ref": "FunctionName"
            }
          }
        },
        "Role": {
          "Type": "ALIYUN::RAM::Role",
          "Properties": {
            "AssumeRolePolicyDocument": {
              "Version": 1,
              "Statement": [
                {
                  "Action": "sts:AssumeRole",
                  "Effect": "Allow",
                  "Principal": {
                    "Service": [
                      "cdn.aliyuncs.com",
                      "fc.aliyuncs.com",
                      "mns.aliyuncs.com",
                      "log.aliyuncs.com",
                      "oss.aliyuncs.com"
                    ]
                  }
                }
              ]
            },
            "Policies": [
              {
                "PolicyName": "FcTrigger",
                "PolicyDocument": {
                  "Version": "1",
                  "Statement": [
                    {
                      "Effect": "Allow",
                      "Action": [
                        "fc:InvokeFunction",
                        "log:PostLogStoreLogs",
                        "dm:*",
                        "dm:BatchSendMail",
                        "dm:SingleSendMail",
                        "dm:Query*"
                      ],
                      "Resource": [
                        "*"
                      ]
                    }
                  ]
                }
              }
            ],
            "RoleName": "Trigger"
          }
        },
        "CdnTrigger": {
          "DependsOn": "Function",
          "Type": "ALIYUN::FC::Trigger",
          "Properties": {
            "ServiceName": {
              "Ref": "ServiceName"
            },
            "FunctionName": {
              "Ref": "FunctionName"
            },
            "TriggerName": "cdn",
            "TriggerType": "cdn_events",
            "SourceArn": {
              "Fn::Sub": "acs:cdn:*:${ALIYUN::TenantId}"
            },
            "InvocationRole": {
              "Fn::GetAtt": [
                "Role",
                "Arn"
              ]
            },
            "TriggerConfig": {
              "EventName": "CachedObjectsBlocked",
              "EventVersion": "1.0.0",
              "Notes": "test",
              "Filter": {
                "Domain": {
                  "Ref": "CdnDomain"
                }
              }
            }
          }
        },
        "LogTrigger": {
          "DependsOn": "Function",
          "Type": "ALIYUN::FC::Trigger",
          "Properties": {
            "ServiceName": {
              "Ref": "ServiceName"
            },
            "FunctionName": {
              "Ref": "FunctionName"
            },
            "TriggerName": "log",
            "TriggerType": "log",
            "SourceArn": {
              "Fn::Join": [
                "",
                [
                  {
                    "Fn::Sub": "acs:log:${ALIYUN::Region}:${ALIYUN::TenantId}:project/"
                  },
                  {
                    "Fn::Select": [
                      "Project",
                      {
                        "Ref": "LogConfig"
                      }
                    ]
                  }
                ]
              ]
            },
            "InvocationRole": {
              "Fn::GetAtt": [
                "Role",
                "Arn"
              ]
            },
            "TriggerConfig": {
              "SourceConfig": {
                "LogStore": {
                  "Ref": "SourceConfigLogStore"
                }
              },
              "LogConfig": {
                "Ref": "LogConfig"
              },
              "JobConfig": {
                "MaxRetryTime": 3,
                "TriggerInterval": 60
              },
              "FunctionParameter": {},
              "Enable": false
            }
          }
        },
        "MnsTrigger": {
          "DependsOn": "Function",
          "Type": "ALIYUN::FC::Trigger",
          "Properties": {
            "ServiceName": {
              "Ref": "ServiceName"
            },
            "FunctionName": {
              "Ref": "FunctionName"
            },
            "TriggerName": "mns",
            "TriggerType": "mns_topic",
            "SourceArn": {
              "Fn::Sub": "acs:mns:${ALIYUN::Region}:${ALIYUN::TenantId}:/topics/${MnsTopic}"
            },
            "InvocationRole": {
              "Fn::GetAtt": [
                "Role",
                "Arn"
              ]
            },
            "TriggerConfig": {
              "NotifyStrategy": "BACKOFF_RETRY",
              "NotifyContentFormat": "STREAM",
              "FilterTag": "test"
            }
          }
        },
        "OssTrigger": {
          "DependsOn": "Function",
          "Type": "ALIYUN::FC::Trigger",
          "Properties": {
            "ServiceName": {
              "Ref": "ServiceName"
            },
            "FunctionName": {
              "Ref": "FunctionName"
            },
            "TriggerName": "oss",
            "TriggerType": "oss",
            "SourceArn": {
              "Fn::Sub": "acs:oss:${ALIYUN::Region}:${ALIYUN::TenantId}:${OssBucketName}"
            },
            "InvocationRole": {
              "Fn::GetAtt": [
                "Role",
                "Arn"
              ]
            },
            "TriggerConfig": {
              "BucketName": {
                "Ref": "OssBucketName"
              },
              "Events": [
                "oss:ObjectCreated:*"
              ],
              "Filter": {
                "Key": {
                  "Prefix": "b",
                  "Suffix": "a"
                }
              }
            }
          }
        },
        "OtsTrigger": {
          "DependsOn": "Function",
          "Type": "ALIYUN::FC::Trigger",
          "Properties": {
            "ServiceName": {
              "Ref": "ServiceName"
            },
            "FunctionName": {
              "Ref": "FunctionName"
            },
            "TriggerName": "ots",
            "TriggerType": "tablestore",
            "SourceArn": {
              "Fn::Sub": "acs:ots:${ALIYUN::Region}:${ALIYUN::TenantId}:instance/${OtsInstance}/table/${OtsTable}"
            },
            "InvocationRole": {
              "Ref": "OtsInvocationRoleArn"
            },
            "TriggerConfig": {
              "InstanceName": {
                "Ref": "OtsInstance"
              },
              "TableName": {
                "Ref": "OtsTable"
              }
            }
          }
        },
        "TimerTrigger": {
          "DependsOn": "Function",
          "Type": "ALIYUN::FC::Trigger",
          "Properties": {
            "ServiceName": {
              "Ref": "ServiceName"
            },
            "FunctionName": {
              "Ref": "FunctionName"
            },
            "TriggerName": "timer",
            "TriggerType": "timer",
            "TriggerConfig": {
              "CronExpression": "0 0/5 * * * *",
              "Enabled": true
            }
          }
        }
      }
    }