ALIYUN::FC3::FunctionInvoker

ALIYUN::FC3::FunctionInvoker类型用于FC3.0 主动执行函数。

语法

{
  "Type": "ALIYUN::FC3::FunctionInvoker",
  "Properties": {
    "FunctionName": String,
    "Async": Boolean,
    "CheckError": Boolean,
    "CheckAsyncInvocation": Map,
    "ExecuteVersion": Integer,
    "Event": String,
    "Qualifier": String,
    "ServiceRegionId": String
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

FunctionName

String

函数名称。

Async

Boolean

是否异步调用。

取值:

  • true

  • false(默认值)

CheckError

Boolean

是否检查调用结果。

取值:

  • true

    说明

    如果取值为true且函数调用结果为失败,则认为资源创建失败。

  • false(默认值)

CheckAsyncInvocation

Map

检查异步调用设置。

更新信息,请参考CheckAsyncInvocation属性

ExecuteVersion

Integer

创建该资源时,如果不指定该参数,则不会触发函数调用,否则触发函数调用。

更新该资源时,如果该参数发生了变化,且变化后的值为整数,则触发函数调用,否则不触发函数调用。

Event

String

用户自定义的函数入参。

该参数在函数执行时会被编码为UTF-8字符串传递给函数。如果需要传递二进制或其他编码的字符串,可以先使用Base64进行编码,再传递给该参数。

Qualifier

String

服务版本。

取值:

  • versionId:版本号。

  • aliasName:别名。

ServiceRegionId

String

函数服务所属地域。

CheckAsyncInvocation语法

"CheckAsyncInvocation": {
  "CheckTimes": Integer,
  "CheckInterval": Integer,
  "Enabled": Boolean
}

CheckAsyncInvocation属性

属性名称

类型

必须

允许更新

描述

约束

CheckTimes

Integer

检查异步调用结果的次数。

默认值为 10 次。

CheckInterval

Integer

检查异步调用结果的间隔时间。

默认值为 10 秒。单位为秒。

Enabled

Boolean

是否检查异步调用结果。

如果设置为 true,且函数调用类型为异步,则资源创建将会等待调用完成并检查结果。默认值为 false。

返回值

Fn::GetAtt

  • ResultType:

    • AsynctrueResultTypeNoResult时,表示没有调用结果。

    • AsyncfalseResultTypeSuccess时,表示执行成功。

    • AsyncfalseResultTypeFailure时,表示执行失败。

  • Result:

    • ResultTypeNoResultResult为空值。

    • ResultTypeSuccessResultinvoke function返回的结果(字符串),具体内容由用户解释。要求返回的结果必须是UTF-8编码的字符串,否则ROS会认为函数执行失败。如果要返回二进制或其他编码的字符串,可以在返回前使用Base64进行编码。

    • ResultTypeFailureResult为报错信息。

示例

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  FunctionName:
    Type: String
    Description:
      en: The name of the function.
    Required: true
Resources:
  FunctionInvoker:
    Type: ALIYUN::FC3::FunctionInvoker
    Properties:
      FunctionName:
        Ref: FunctionName
Outputs:
  ResultType:
    Description: |-
      Result type:
      NoResult: Async invoke has no result.
      Success: Sync invoke succeeds.
      Failure: Sync invoke fails.
    Value:
      Fn::GetAtt:
        - FunctionInvoker
        - ResultType
  Result:
    Description: |-
      Depends on result type:
      NoResult: Async invoke has no result.
      Success: The response of the function. The response should be utf-8 encoded string, otherwise ROS will report an error. If the response is binary, encode it via base64 before it is returned.
      Failure: Error Message.
    Value:
      Fn::GetAtt:
        - FunctionInvoker
        - Result
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "FunctionName": {
      "Type": "String",
      "Description": {
        "en": "The name of the function."
      },
      "Required": true
    }
  },
  "Resources": {
    "FunctionInvoker": {
      "Type": "ALIYUN::FC3::FunctionInvoker",
      "Properties": {
        "FunctionName": {
          "Ref": "FunctionName"
        }
      }
    }
  },
  "Outputs": {
    "ResultType": {
      "Description": "Result type:\nNoResult: Async invoke has no result.\nSuccess: Sync invoke succeeds.\nFailure: Sync invoke fails.",
      "Value": {
        "Fn::GetAtt": [
          "FunctionInvoker",
          "ResultType"
        ]
      }
    },
    "Result": {
      "Description": "Depends on result type:\nNoResult: Async invoke has no result.\nSuccess: The response of the function. The response should be utf-8 encoded string, otherwise ROS will report an error. If the response is binary, encode it via base64 before it is returned.\nFailure: Error Message.",
      "Value": {
        "Fn::GetAtt": [
          "FunctionInvoker",
          "Result"
        ]
      }
    }
  }
}