ALIYUN::FC::FunctionInvoker

ALIYUN::FC::FunctionInvoker类型用于主动执行函数。

语法

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

属性

属性名称

类型

必须

允许更新

描述

约束

ServiceName

String

服务名称。

长度为1~128个字符。

FunctionName

String

函数名称。

Async

Boolean

是否异步调用。

取值:

  • true

  • false(默认值)

Event

String

用户自定义的函数入参。

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

Qualifier

String

服务版本。

取值:

  • versionId:版本号。

  • aliasName:别名。

ExecuteVersion

Integer

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

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

CheckError

Boolean

是否检查调用结果。

取值:

  • true

    说明

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

  • false(默认值)

ServiceRegionId

String

函数服务所属地域。

CheckAsyncInvocation

Map

检查异步调用设置。

更新信息,请参考CheckAsyncInvocation属性。

CheckAsyncInvocation语法

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

CheckAsyncInvocation属性

属性名称

类型

必须

允许更新

描述

约束

Enabled

Boolean

是否检查异步调用结果。

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

CheckInterval

Integer

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

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

CheckTimes

Integer

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

默认值为 10 次。

返回值

Fn::GetAtt

  • ResultType:

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

    • AsyncfalseResultTypeSuccess时,表示执行成功。

    • AsyncfalseResultTypeFailure时,表示执行失败。

  • Result:

    • ResultTypeNoResultResult为空值。

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

    • ResultTypeFailureResult为报错信息。

示例

ROSTemplateFormatVersion: '2015-09-01'
Parameters: {}
Resources:
  FunctionInvoker:
    Type: ALIYUN::FC::FunctionInvoker
    Properties:
      ServiceName: mytest
      FunctionName: PythonFunc
      ExecuteVersion: 1
Outputs: {}
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
  },
  "Resources": {
    "FunctionInvoker": {
      "Type": "ALIYUN::FC::FunctionInvoker",
      "Properties": {
        "ServiceName": "mytest",
        "FunctionName": "PythonFunc",
        "ExecuteVersion": 1.0
      }
    }
  },
  "Outputs": {
  }
}