すべてのプロダクト
Search
ドキュメントセンター

Resource Orchestration Service:ALIYUN::FC::Trigger

最終更新日:Jan 16, 2025

ALIYUN::FC::Trigger は、関数の呼び出しをトリガーするために使用されます。

イベント駆動型コンピューティングモデルでは、イベントソースがイベントを生成し、関数がイベントを処理し、トリガーはさまざまなイベントソースを一元的に管理するために使用されます。イベントソース側では、トリガーによって定義されたルールに一致するイベントが発生すると、イベントソースは関連する関数を呼び出します。

構文

{
  "Type": "ALIYUN::FC::Trigger",
  "Properties": {
    "TriggerConfig": Map, // トリガーの設定
    "InvocationRole": String, // 呼び出しロール
    "FunctionName": String, // 関数名
    "ServiceName": String, // サービス名
    "TriggerName": String, // トリガー名
    "TriggerType": String, // トリガータイプ
    "Qualifier": String, // バージョン
    "SourceArn": String // イベントソースのARN
  }
}

プロパティ

プロパティ

タイプ

必須

編集可能

説明

制約

ServiceName

String

はい

いいえ

関数が属するサービスの名前。

名前の長さは 1 ~ 128 文字である必要があります。

FunctionName

String

はい

いいえ

トリガーを作成する関数の名前。

なし。

TriggerName

String

はい

いいえ

トリガーの名前。

名前の長さは 1 ~ 128 文字で、数字、文字、ハイフン(-)、アンダースコア(_)を含めることができます。名前は文字またはアンダースコア(_)で始まる必要があります。

TriggerType

String

はい

いいえ

トリガーのタイプ。

有効な値:

  • oss: オブジェクトストレージサービス(OSS)トリガー

  • log: ログサービストリガー

  • tablestore: Tablestoreトリガー

  • timer: 時間トリガー

  • mns_topic: メッセージサービス(MNS)トピックトリガー

  • cdn_events: Alibaba Cloud CDN(CDN)イベントトリガー

  • http: HTTP トリガー

    説明

    HTTP トリガーは、関数の作成時にのみ作成できます。関数の HTTP トリガーが構成されている場合、その関数に対して他の種類のトリガーを作成することはできません。

TriggerConfig

Map

はい

はい

トリガーの設定。

設定はトリガータイプによって異なります。

InvocationRole

String

いいえ

はい

イベントソースに関数を呼び出す権限を付与するために使用されるトリガーロール。例:acs:ram::164696547407****:role/fc-test

このプロパティは、TriggerType が timer または http に設定されている場合はオプションです。TriggerType が timer および http 以外の値に設定されている場合は必須です。

次のセクションでは、さまざまなタイプのトリガーのロール認証の信頼できるエンティティとポリシーを示します。

  • oss

    • 信頼できるエンティティ: oss.aliyuncs.com

    • ポリシーのアクション: fc:InvokeFunction

  • log

    • 信頼できるエンティティ: log.aliyuncs.com

    • ポリシーのアクション: log:PostLogStoreLogs

  • tablestore

    • 信頼できるエンティティ: 1604337383174****

    • ポリシーのアクション: fc:InvokeFunction、ots:BatchGet*、ots:Describe*、ots:Get*、および ots:List*

  • mns_topic

    • 信頼できるエンティティ: mns.aliyuncs.com

    • ポリシーのアクション: dm:BatchSendMail、dm:SingleSendMail、および dm:Query

  • cdn_events

    • 信頼できるエンティティ: cdn.aliyuncs.com

    • ポリシーのアクション: fc:InvokeFunction

SourceArn

String

いいえ

いいえ

イベントソースのAlibaba Cloud Resource Name(ARN)。

このプロパティは、TriggerType が timer または http に設定されている場合はオプションです。TriggerType が timer および http 以外の値に設定されている場合は必須です。

次のセクションでは、さまざまなタイプのトリガーのイベントソース ARN の形式と例を示します。

  • oss

    • 形式:acs:oss:<RegionId>:<TenantId>:<OssBucketName>

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

  • log

    • 形式:acs:log:<RegionId>:<TenantId>:project/<LogConfig の Project の値>

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

  • tablestore

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

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

  • mns_topic

    • 形式:acs:mns:<RegionId>:<TenantId>:/topics/<MnsTopic>

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

  • cdn_events

    • 形式:acs:cdn:*:<TenantId>

    • 例:acs:cdn:*:164696547407****

説明

TenantId は、Alibaba Cloud アカウント ID に置き換えてください。

Qualifier

String

いいえ

はい

トリガーのバージョン。

デフォルト値:LATEST。

oss-TriggerConfig 構文

"TriggerConfig": {
  "BucketName": String, // バケット名
  "Events": List, // イベント
  "Filter": Map // フィルター
}      

oss-TriggerConfig プロパティ

プロパティ

タイプ

必須

編集可能

説明

制約

BucketName

String

はい

いいえ

バケットの名前。

イベントソースとして OSS バケットを選択する必要があります。同じリージョン内のバケットが [バケット] ドロップダウンリストに表示されます。

Events

String

はい

はい

トリガーイベント。Alibaba Cloud リソースで実行される操作を表します。

例:oss:ObjectCreated:*

Filter

Map

いいえ

はい

トリガールール。循環トリガーを回避するために使用されます。

Prefix および Suffix の値はカスタム文字列である必要があります。

例:

"Filter": {
  "Key": {
    "Prefix": "prefix", // プレフィックス
    "Suffix": "suffix" // サフィックス
  }
}

log-TriggerConfig 構文

"TriggerConfig": {
  "SourceConfig": Map, // ソース設定
  "LogConfig": Map, // ログ設定
  "JobConfig": Map, // ジョブ設定
  "FunctionParameter": Map, // 関数パラメーター
  "Enable": Boolean // 有効化
}

log-TriggerConfig プロパティ

プロパティ

タイプ

必須

編集可能

説明

制約

SourceConfig

Map

はい

いいえ

Logstore の設定。

例:{"LogStore": "<SLS_LogStore>"}

LogConfig

Map

はい

はい

トリガーのログサービス プロジェクトと Logstore の設定。

Project: ログサービス プロジェクト。このプロパティは必須ですが、編集できません。LogStore: トリガーの Logstore。このプロパティはオプションで、編集可能です。Logstore は、SourceConfig プロパティの LogStore の値と同じにすることはできません。

例:{"Project": "<SLS_Project>", "LogStore": "SLS_LogStore"}

JobConfig

Map

はい

はい

トリガー設定。最大再試行回数とトリガー間隔を指定します。

MaxRetryTime: トリガー間隔。単位:秒。

TriggerInterval: 最大再試行回数。有効な値:0 ~ 100。

例:{"MaxRetryTime": 3, "TriggerInterval": 60}

FunctionParameter

Map

はい

はい

関数にパラメーターを渡すために使用される関数設定。

パラメーターを渡さない場合は、値を中括弧({})に設定します。

Enable

Boolean

はい

はい

トリガーを有効にするかどうかを指定します。

有効な値:

  • true

  • false

timer-TriggerConfig 構文

"TriggerConfig": {
  "Payload": String, // トリガーメッセージ
  "CronExpression": String, // cron式
  "Enabled": Boolean // 有効化
}

timer-TriggerConfig プロパティ

プロパティ

タイプ

必須

編集可能

説明

制約

Payload

String

いいえ

はい

トリガーメッセージ。

なし。

CronExpression

String

はい

はい

トリガー時間を指定するために使用される CRON 式。

CRON 式は協定世界時(UTC)を使用します。

Enabled

Boolean

はい

はい

トリガーを有効にするかどうかを指定します。

有効な値:

  • true

  • false

tablestore-TriggerConfig 構文

"TriggerConfig",: {
  "InstanceName": String, // インスタンス名
  "TableName": String // テーブル名
}

tablestore-TriggerConfig プロパティ

プロパティ

タイプ

必須

編集可能

説明

制約

InstanceName

String

はい

いいえ

Tablestore インスタンスの名前。

なし。

TableName

String

はい

いいえ

データテーブルの名前。

なし。

mns_topic-TriggerConfig 構文

"TriggerConfig": {
  "NotifyStrategy": String, // 再試行ポリシー
  "NotifyContentFormat": String, // イベントの形式
  "FilterTag": String // フィルタータグ
}

mns_topic-TriggerConfig プロパティ

プロパティ

タイプ

必須

編集可能

説明

制約

NotifyStrategy

String

はい

いいえ

再試行ポリシー。

有効な値:

  • BACKOFF_RETRY

  • EXPONENTIAL_DECAY_RETRY

詳細については、「NotifyStrategy」をご参照ください。

NotifyContentFormat

String

はい

いいえ

イベントの形式。

有効な値:

  • STREAM

  • JSON

FilterTag

String

いいえ

いいえ

フィルタータグ。

なし。

cdn-TriggerConfig 構文

"TriggerConfig": {
  "EventName": String, // イベント名
  "EventVersion": String, // イベントのバージョン
  "Notes": String, // 備考
  "Filter": List // フィルター
}

cdn-TriggerConfig プロパティ

プロパティ

タイプ

必須

編集可能

説明

制約

EventName

String

はい

いいえ

トリガーイベント。

有効な値:

  • CachedObjectsBlocked

  • CachedObjectsPushed

  • CachedObjectsRefreshed

  • LogFileCreated

  • CdnDomainStarted

  • CdnDomainStopped

  • CdnDomainAdded

  • CdnDomainDeleted

EventVersion

String

はい

いいえ

トリガーイベントのバージョン。

なし。

Notes

String

はい

はい

備考。

なし。

Filter

List

はい

はい

フィルター。

各フィルターのキーは Domain です。少なくとも 1 つのフィルターを指定する必要があります。例:[{"Domain": "example.com"}, {"Domain": "example.org"}, ...]

http-TriggerConfig 構文

説明

HTTPトリガーは、関数を作成するときにのみ作成できます。関数がHTTPトリガーで設定されている場合、関数に対して他のタイプのトリガーを作成することはできません。

"TriggerConfig": {
  "AuthType": String, // 認証方式
  "Methods": List // リクエストメソッド
}

http-TriggerConfig プロパティ

プロパティ

タイプ

必須

編集可能

説明

制約

AuthType

String

はい

いいえ

認証方式。

有効な値:

  • anonymous

  • function

Methods

List

はい

いいえ

リクエストメソッド。

有効な値:

  • GET

  • POST

  • PUT

  • DELETE

  • HEAD

  • PATCH

例:["GET"] および ["POST", "PUT"]

戻り値

Fn::GetAtt

  • TriggerId: 各トリガーに対してシステムによって生成される一意の ID。

  • ServiceName: 関数が属するサービスの名前。

  • FunctionName: 関数の名前。

  • TriggerName: トリガーの名前。

  • UrlInternet: パブリックドメインアドレス。

  • UrlIntranet: プライベートドメインアドレス。

  • YAML 形式

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      ServiceName:
        Type: String
      FunctionName:
        Type: String
      CdnDomain:
        Type: Json
      SourceConfigLogStore:
        Type: String
      LogConfig:
        Type: Json
        Description: '例: {"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 形式

    {
      "ROSTemplateFormatVersion": "2015-09-01",
      "Parameters": {
        "ServiceName": {
          "Type": "String"
        },
        "FunctionName": {
          "Type": "String"
        },
        "CdnDomain": {
          "Type": "Json"
        },
        "SourceConfigLogStore": {
          "Type": "String"
        },
        "LogConfig": {
          "Type": "Json",
          "Description": "例: {\"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
            }
          }
        }
      }
    }