ALIYUN::FC::Function is used to create a function. Functions must be associated with services. All functions of a service share the same attributes as the service, such as service authorization and log configurations.
Syntax
{
"Type": "ALIYUN::FC::Function",
"Properties": {
"Code": Map,
"FunctionName": String,
"ServiceName": String,
"InstanceType": String,
"MemorySize": Integer,
"InstanceConcurrency": Integer,
"EnvironmentVariables": Map,
"Initializer": String,
"Handler": String,
"Timeout": Integer,
"InitializationTimeout": Integer,
"CustomContainerConfig": Map,
"AsyncConfiguration": Map,
"CAPort": Integer,
"Runtime": String,
"Description": String,
"Cpu": Number,
"CustomRuntimeConfig": Map,
"GpuMemorySize": Integer,
"InstanceSoftConcurrency": Integer,
"DiskSize": Integer,
"InstanceLifecycleConfig": Map,
"CustomDNS": Map,
"CustomHealthCheckConfig": Map
}
}
Properties
Property | Type | Required | Editable | Description | Constraint |
Initializer | String | No | Yes | The handler of the Initializer hook. | The format of the value varies based on the programming language that you use. |
InitializationTimeout | Integer | No | Yes | The timeout period for the execution of the Initializer hook. | Valid values: 1 to 300. Unit: seconds. Default value: 3. When the timeout period ends, Function Compute terminates the execution of the Initializer hook. |
Code | Map | No | Yes | The code package in the ZIP format. | For more information, see Code properties. |
InstanceType | String | No | Yes | The type of the function instance. | Valid values:
|
Description | String | No | Yes | The description of the function. | None. |
ServiceName | String | Yes | No | The name of the service in Function Compute. | The name must be 1 to 128 characters in length. |
MemorySize | Integer | No | Yes | The memory size of the function. |
Unit: MB. |
InstanceConcurrency | Integer | No | Yes | The number of concurrent requests on the instance. | Valid values: 1 to 100. Note This property is unavailable for Python function instances. |
EnvironmentVariables | Map | No | Yes | The environment variables that you want to configure for the function. | None. |
Handler | String | Yes | Yes | The handler of the function. | For example, if you set Handler to index.handler when you create a Python function, the file name is index.py and the method name is handler. The format of the value varies based on the programming language that you use. |
Timeout | Integer | No | Yes | The timeout period for the execution of the function. | Valid values: 1 to 600. Default value: 3. Unit: seconds. When the timeout period ends, Function Compute terminates the execution of the function. |
Runtime | String | Yes | Yes | The runtime environment of the function. | Valid values: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, custom, and custom-container. For more information, see Runtimes that are supported by Function Compute. |
FunctionName | String | Yes | No | The function name. | The name must be 1 to 128 characters in length and can contain letters, digits, underscores (_), and hyphens (-). The name must start with a letter or an underscore (_). |
CustomContainerConfig | Map | No | Yes | The configurations of the custom container if you set Runtime to custom-container. After you specify the configurations, you can use a custom container image to invoke the function. | For more information, see CustomContainerConfig properties. |
CAPort | Integer | No | Yes | The port on which the custom HTTP server listens. | Default value: 9000. Note This property takes effect when Runtime is set to custom or custom-container. |
AsyncConfiguration | Map | No | Yes | The asynchronous invocation configurations. | For more information, see AsyncConfiguration properties. |
Cpu | Number | No | Yes | The CPU specification of the function. | None. |
CustomRuntimeConfig | Map | No | Yes | The configurations of the custom runtime for the function. | None. |
GpuMemorySize | Integer | No | Yes | The GPU memory size of the function. | The value must be a multiple of 1024. Unit: MB. |
InstanceSoftConcurrency | Integer | No | Yes | The soft concurrency of the instance. You can use this property to implement graceful scale-ups for instances. | If the number of concurrent requests on an instance is greater than the soft concurrency value of the instance, an instance scale-up is triggered. For example, if your instance requires a long time to start, you can specify a suitable soft concurrency value to start the instance in advance. The value must be less than or equal to the value of InstanceConcurrency. |
DiskSize | Integer | No | Yes | The disk size of the function. | Unit: MB. Valid values: 512 and 10240. |
InstanceLifecycleConfig | Map | No | Yes | The instance lifecycle configurations of the function. | For more information, see InstanceLifecycleConfig properties. |
CustomDNS | Map | No | Yes | The custom Domain Name System (DNS) configurations of the function. | For more information, see CustomDNS properties. |
CustomHealthCheckConfig | Map | No | Yes | The health check configurations of the custom runtime and custom container. | For more information, see CustomHealthCheckConfig properties. |
Code syntax
"Code": {
"OssBucketName": String,
"OssObjectName": String,
"ZipFile": String,
"SourceCode": String
}
Code properties
Property | Type | Required | Editable | Description | Constraint |
OssBucketName | String | No | Yes | The name of the Object Storage Service (OSS) bucket in which the code package is stored. | None. |
OssObjectName | String | No | Yes | The name of the code package that is used as an OSS object. | None. |
ZipFile | String | No | Yes | The Base64-encoded content of the code package. | None. |
SourceCode | String | No | Yes | The source code of the function. | The source code can be up to 4,096 characters in length. Node.js, PHP, and Python are supported. Resource Orchestration Service (ROS) writes the value of this property to a UTF-8 encoded file named index. When you specify the ZipFile, SourceCode, OssBucketName, and OssObjectName properties, the properties are in descending order of priority. |
CustomContainerConfig syntax
"CustomContainerConfig": {
"Command": String,
"Args": String,
"Image": String,
"AccelerationType": String,
"InstanceId": String,
"WebServerMode": Boolean
}
CustomContainerConfig properties
Property | Type | Required | Editable | Description | Constraint |
Command | String | No | Yes | The startup command of the container. | Example: |
Args | String | No | Yes | The arguments that you want to pass to the startup command of the container. | Example: |
Image | String | Yes | Yes | The endpoint of the container image. | Example: |
AccelerationType | String | No | Yes | Specifies whether to enable image acceleration. | Valid values:
|
InstanceId | String | No | Yes | The ID of the Container Registry Enterprise Edition instance. | If you use a Container Registry Enterprise Edition instance, you must specify the instance ID. The default resolved IP address of the instance must be the IP address of a virtual private cloud (VPC) in which Container Registry resides. Note You cannot use Alibaba Cloud DNS PrivateZone to define domain name resolution. |
WebServerMode | Boolean | No | Yes | Specifies whether to use the web server mode to run images. | Valid values:
|
AsyncConfiguration syntax
"AsyncConfiguration": {
"Destination": Map
"MaxAsyncRetryAttempts": Integer,
"MaxAsyncEventAgeInSeconds": Integer,
"StatefulInvocation": Boolean
}
AsyncConfiguration properties
Property | Type | Required | Editable | Description | Constraint |
Destination | Map | No | No | The destination for the asynchronous invocation. | For more information, see Destination properties. |
MaxAsyncRetryAttempts | Integer | No | Yes | The maximum number of retries. | None. |
MaxAsyncEventAgeInSeconds | Integer | No | Yes | The maximum validity period of messages. | None. |
StatefulInvocation | Boolean | No | Yes | Specifies whether to enable stateful asynchronous invocations. | Valid values:
For more information, see Overview. |
Destination syntax
"Destination": {
"OnSuccess": String,
"OnFailure": String
}
Destination properties
Property | Type | Required | Editable | Description | Constraint |
OnSuccess | String | No | Yes | The destination that Function Compute invokes when the function execution is successful. | None. |
OnFailure | String | No | Yes | The destination that Function Compute invokes when the function execution fails due to a system error or a built-in function error. | None. |
InstanceLifecycleConfig syntax
"InstanceLifecycleConfig":{
"PreFreeze": Map,
"PreStop": Map
}
InstanceLifecycleConfig properties
Property | Type | Required | Editable | Description | Constraint |
PreFreeze | Map | No | Yes | The configurations of the PreFreeze hook. | For more information, see PreFreeze properties. |
PreStop | Map | No | Yes | The configurations of the PreStop hook. | For more information, see PreStop properties. |
PreStop syntax
"PreStop":{
"Handler": String,
"Timeout": Integer
}
PreStop properties
Property | Type | Required | Editable | Description | Constraint |
Handler | String | No | Yes | The handler of the function. | For more information, see Basics. |
Timeout | Integer | No | Yes | The timeout period for the execution. | Unit: seconds. |
PreFreeze syntax
"PreFreeze":{
"Handler": String,
"Timeout": Integer
}
PreFreeze properties
Property | Type | Required | Editable | Description | Constraint |
Handler | String | No | Yes | The handler of the function. | For more information, see Basics. |
Timeout | Integer | No | Yes | The timeout period for the execution. | Unit: seconds. |
CustomHealthCheckConfig syntax
"CustomHealthCheckConfig":{
"SuccessThreshold": Integer,
"InitialDelaySeconds": Integer,
"PeriodSeconds": Integer,
"HttpGetUrl": String,
"TimeoutSeconds": Integer,
"FailureThreshold": Integer
}
CustomHealthCheckConfig properties
Property | Type | Required | Editable | Description | Constraint |
SuccessThreshold | Integer | No | Yes | The number of times that a container must consecutively pass health checks before it is declared healthy. |
Valid values: 1 to 120. Default value: 1. |
InitialDelaySeconds | Integer | No | Yes | The delay between the container startup and the health check. | Valid values: 0 to 120. Default value: 0. |
PeriodSeconds | Integer | No | Yes | The health check period. | Valid values: 1 to 120. Default value: 3. |
HttpGetUrl | String | No | Yes | The custom health check URL of the container. | The URL can be up to 2,048 characters in length. |
TimeoutSeconds | Integer | No | Yes | The timeout period of a health check. | Valid values: 1 to 3. Default value: 1. |
FailureThreshold | Integer | No | Yes | The number of times that a container must consecutively fail health checks before it is declared unhealthy. |
Valid values: 1 to 120. Default value: 3. |
CustomRuntimeConfig syntax
"CustomRuntimeConfig":{
"Args": List,
"Command": List,
}
CustomRuntimeConfig properties
Property | Type | Required | Editable | Description | Constraint |
Args | List | No | Yes | The parameters received for the startup command. | Example:
|
Command | List | No | Yes | The startup command. | Example:
|
CustomDNS syntax
"CustomDNS":{
"NameServers": List,
"DnsOptions": List,
"Searches": List
}
CustomDNS properties
Property | Type | Required | Editable | Description | Constraint |
NameServers | List | No | Yes | The IP addresses of the DNS servers. | None. |
DnsOptions | List | No | Yes | The configuration items in the | None. |
Searches | List | No | Yes | The DNS search domains. | None. |
DnsOptions syntax
"DnsOptions":{
"Value": String,
"Name": String,
}
DnsOptions properties
Property | Type | Required | Editable | Description | Constraint |
Value | String | No | Yes | The value of the configuration item. | Example: 2. |
Name | String | Yes | Yes | The name of the configuration item. | Example: ndots. |
Return values
Fn::GetAtt
FunctionId: the unique ID that is generated by the system for the function.
ServiceName: the name of the service in Function Compute.
ARN: the Alibaba Cloud Resource Name (ARN) of the function.
FunctionName: the function name.
ServiceId: the ID of the service in Function Compute.
Examples
For more examples, visit function-invoker.yml. In the examples, the following resource types are used:
ALIYUN::FC::Service
ALIYUN::FC::Function
ALIYUN::FC::FunctionInvoker
ALIYUN::FC::Trigger
ALIYUN::FC::Version
ALIYUN::FC::Alias
ALIYUN::FC::ProvisionConfig