This topic describes the YAML syntax of the FC component and related parameters.
YAML file
The following example shows the YAML file of the FC component:
edition: 1.0.0 # The version of the YAML syntax. The version complies with the semantic versioning specification.
name: ffmpeg-app # The name of the project.
access: default # The alias of the key.
services:
fc-deploy-test: # The name of the service.
component: devsapp/fc # The name of the component.
props: # The properties of the component.
region: cn-qingdao
service:
name: fc-deploy-service
description: demo for fc-deploy component
internetAccess: true
role: 'acs:ram::xxx:role/test-fc-deploy-test-role'
tracingConfig: Enable
nasConfig:
userId: 10003
groupId: 10003
mountPoints:
- serverAddr: xxx.cn-qingdao.nas.aliyuncs.com
nasDir: /test-fc-deploy-service
fcDir: /mnt/auto
vpcConfig:
vpcId: xxx
securityGroupId: xxx
vSwitchIds:
- vsw-xxx
logConfig:
project: xxx
logstore: xxx
enableRequestMetrics: true
enableInstanceMetrics: true
logBeginRule: DefaultRegex
function:
name: fc-base-service
description: 'this is test'
codeUri: './code.zip'
ossBucket: xxx
ossKey: xxx
handler: 'index.handler'
memorySize: 128
runtime: nodejs12
timeout: 60
caPort: 9000
customContainerConfig:
image: xxx
command: xxx
args: xxx
instanceID: cri-xxxxxx
accelerationType: Default
environmentVariables:
key: 'value'
initializationTimeout: 20
initializer: index.initializer
instanceConcurrency: 1
instanceType: e1
layers: <layerARN>
instanceLifecycleConfig:
preFreeze:
handler: index.xxx
timeout: 60
preStop:
handler: index.xxx
preStop: 60
asyncConfiguration:
destination:
onSuccess: acs:fc:{region}:{uid}:services/{serviceName}.{qualifier}/functions/{functionName}
onFailure: acs:fc:{region}:{uid}:services/{serviceName}.{qualifier}/functions/{functionName}
# onSuccess: acs:fc:::services/{serviceName}.{qualifier}/functions/{functionName}
# onSuccess: acs:mns:::/queues/{queuesName}/messages # mns/queues
# onSuccess: acs:mns:::/topics/{topicsName}/messages # mns/topics
maxAsyncEventAgeInSeconds: 456
maxAsyncRetryAttempts: 3
statefulInvocation: true
triggers:
- name: httpTrigger
type: http
qualifier: xxx
config:
authType: anonymous
methods:
- GET
- name: timerTrigger
type: timer
qualifier: xxx
config:
cronExpression: '0 0 8 * * *'
enable: true
payload: 'awesome-fc'
- name: ossTrigger
type: oss
qualifier: xxx
role: xxx
sourceArn: xxx
config:
bucketName: fassdemo
events:
- oss:ObjectCreated:*
- oss:ObjectRemoved:DeleteObject
filter:
Key:
Prefix: source/
Suffix: .png
- name: logTrigger
type: log
qualifier: xxx
role: xxx
sourceArn: xxx
config:
logConfig:
project: fass-demo
logstore: fc-log
jobConfig:
maxRetryTime: 1
triggerInterval: 30
sourceConfig:
logstore: function-log
functionParameter:
key: val
enable: true
- name: mnsTrigger
type: mns_topic
qualifier: xxx
role: xxx
sourceArn: xxx
config:
topicName: test-topic
region: cn-hangzhou
notifyContentFormat: 'JSON'
notifyStrategy: 'BACKOFF_RETRY'
- name: cdnTrigger
type: cdn_events
qualifier: xxx
role: xxx
sourceArn: xxx
config:
eventName: LogFileCreated
eventVersion: '1.0.0'
notes: cdn events trigger test
filter:
domain:
- 'www.taobao.com'
- 'www.example.com'
- name: otsTrigger
sourceArn: acs:ots:<region>:<account-id>:instance/<instance>/table/<table>
type: tablestore
role: acs:ram::<account-id>:role/AliyunTableStoreStreamNotificationRole
qualifier: xxx
config:
instanceName: xxx
tableName: test
customDomains:
- domainName: auto
protocol: HTTP
routeConfigs:
- path: /a
serviceName: test-fc-deploy-service
functionName: custom-container-function
methods:
- GET
certConfig:
certName: xxx
certificate: xxx
privateKey: xxx
Fields
The following table describes the fields in the YAML file.
Field | Required | Type | Description |
---|---|---|---|
region | Yes | Enum | The ID of the region where resources are deployed. For more information about supported regions, see Endpoints. |
service | Yes | Struct | The details of the service. For more information, see service. |
function | No | Struct | The details of the function. For more information, see function. |
triggers | No | Struct | The details of the triggers. For more information, see triggers. |
customDomains | No | Struct | The details of the custom domain names. For more information, see customDomains. |
service
Parameter | Required | Type | Description |
---|---|---|---|
name | Yes | String | The name of the service. |
description | No | String | The description of the service. |
internetAccess | No | Boolean | Specifies whether to allow functions in the specified service to access the Internet.
Valid values:
|
tracingConfig | No | String | Specifies whether to enable Tracing Analysis. Valid values:
|
role | No | This parameter supports the following two types:
|
The RAM role that is used to grant required permissions to Function Compute.
The RAM role is used in the following scenarios:
For more information, see role.
|
logConfig | No | This parameter supports the following two types:
|
The log configuration. Function Compute writes function execution logs to the specified Logstore. For more information, see logConfig. |
vpcConfig | No | This parameter supports the following two types:
|
The Virtual Private Cloud (VPC) configuration, which allows functions in the specified service in Function Compute to access the specified VPC. For more information, see vpcConfig. |
nasConfig | No | This parameter supports the following two types:
|
The configuration of the Apsara File Storage NAS file system, which allows functions in the specified service in Function Compute to access the NAS file system. For more information, see nasConfig. |
role
Values of the
role
parameter of different types:
- String: The value of the
role
parameter is a string in the format ofacs:ram::xxx:role/test-fc-deploy-test-role
. - Struct: The value of the
role
parameter is a structure. The following table describes the parameters contained in therole
parameter.Parameter Required Type Description name Yes String The name of the RAM role. policies Yes List The policies attached to the RAM role. policies
In the list of thepolicies
parameter, each element can be astring
orpolicy
structure. The following table describes the parameters contained in each structure.Parameter Required Type Description name Yes String The name of the policy. description No String The description of the policy. statement Yes List The content of the policy. statement
In the list of theThe following sample code shows thestatement
parameter, each element is a structure. The following table describes the parameters contained in each structure.Parameter Required Type Description Effect Yes String The authorization effect of the policy. Valid values: Allow
: allows the operation.Deny
: denies the operation.
Action Yes List The operation that is allowed or denied. Resource Yes String or List The resource on which the permissions are granted. Condition No Object The condition required for the policy to take effect. role
parameter whose value is a structure:role: name: roleName policies: - AliyunOSSFullAccess - name: myPolicy description: custom policy statement: - Effect: Allow Action: - log:ListProject Resource: - acs:log:*:*:project/*
logConfig
The
logCofig
parameter supports the following types:
- String: The value of the
logConfig
parameter is a string. In this case, set this parameter toauto
. - Struct: The value of the
logConfig
parameter is a structure. The following table describes the parameters contained in the logConfig parameter.Parameter Required Type Description logStore Yes String The name of the Logstore in Log Service. project Yes String The name of the project in Log Service. enableRequestMetrics No Boolean Specifies whether to enable the collection of request-level metrics. If you enable this feature, you can view the amount of time and memory consumed for a specific invocation of each function in the service. Valid values: true
: enables the collection of request-level metrics.false
: disables the collection of request-level metrics.
enableInstanceMetrics No Boolean Specifies whether to enable the collection of instance-level metrics. If you enable this feature, you can view core metrics such as CPU utilization, memory usage, the network conditions of instances, and the number of requests that an instance concurrently processes. Valid values: true
: enables the collection of instance-level metrics.false
: disables the collection of instance-level metrics.
logBeginRule No String Specifies whether to enable log segmentation. Valid values: None
: disables log segmentation. This is the default value.DefaultRegex
: enables log segmentation. After log segmentation is enabled, Function Compute segments function execution logs and stores log segments in Log Service. Function Compute segments function execution logs based on the lines with the date information. For example, if the first line of a log is 2021-10-10, this line is regarded as the first line of a log segment, and the subsequent consecutive lines that do not contain a date are regarded as the remaining content of the log segment.
vpcConfig
The
vpcConfig
parameter supports the following types:
- String: The value of the
vpcConfig
parameter is a string. In this case, set this parameter toauto
. - Struct: The value of the
vpcConfig
parameter is a structure. The following table describes the parameters contained in the vpcConfig parameter.Parameter Required Type Description securityGroupId Yes String The ID of the security group. vSwitchIds Yes List The IDs of one or more vSwitches. vpcId Yes String The ID of the VPC.
nasConfig
The
nasConfig
parameter supports the following types:
- String: The value of the
nasConfig
parameter is a string. In this case, set this parameter toauto
. - Struct: The value of the
nasConfig
parameter is a structure. The following table describes the parameters contained in the nasConfig parameter.Parameter Required Type Description mountPoints Yes List The directories. For more information, see mountPoints. userId No String The ID of the account. Default value: 10003. groupId No String The ID of the group. Default value: 10003.
mountPoints
Parameter | Required | Type | Description |
---|---|---|---|
serverAddr | Yes | String | The address of the NAS server. |
nasDir | Yes | String | The directory of NAS. |
fcDir | Yes | String | The directory of Function Compute. |
function
The following table describes the parameters contained in the function field.
Parameter | Required | Type | Description |
---|---|---|---|
name | Yes | String | The name of the function. |
description | No | String | The description of the function. |
codeUri | No | String | The directory where the code is located. |
ossBucket | No | String | The Object Storage Service (OSS) bucket that stores the code. This parameter cannot
be specified together with the codeUri parameter.
|
ossKey | No | String | The object that contains the code in OSS. This parameter cannot be specified together
with the codeUri parameter.
|
handler | No | String | The handler that is used by Function Compute to invoke the function. The format is determined by the programming language. For more information, see Function handler. |
memorySize | No | Number | The memory size for the function. Unit: MB. The memory size is a multiple of 64 MB. Different types of instances are allocated different memory sizes. For more information, see the "Instance specifications" section of the Instance types and instance modes topic. |
runtime | Yes | String | The runtime environment of the function. Valid values: nodejs6 , nodejs8 , nodejs10 , nodejs12 , nodejs14 , python2.7 , python3 , java8 , java11 , php7.2 , dotnetcore2.1 , go1 , custom , and custom-container .
|
timeout | No | Number | The timeout period for the execution of the function. Unit: seconds. Default value: 60. Valid values: [1,86400]. When this period expires, the execution of the function is terminated. |
caPort | No | Number | The port on which the HTTP server listens for the custom runtime or custom container. |
customContainerConfig | No | Struct | The configuration of the custom container. After you configure the custom container, Function Compute can execute functions in a container created from a custom image. For more information, see customContainerConfig. |
environmentVariables | No | List | The environment variables configured for the function. You can obtain the values of the environment variables from the function. This parameter is of the OBJECT type. For more information, see Environment variables. |
initializationTimeout | No | Number | The timeout period for the execution of the initializer function. Unit: seconds. Default value: 3. Valid values: [1,300]. When this period expires, the execution of the initializer function is terminated. |
initializer | No | String | The handler of the initializer function. The format is determined by the programming language. For more information, see Initializer function. |
instanceConcurrency | No | Number | The maximum number of requests that a single instance can concurrently process. |
instanceType | No | String | The type of the instance that executes the function. Valid values:
|
instanceLifecycleConfig | No | Struct | The extension functions. For more information, see instanceLifecycleConfig. |
asyncConfiguration | No | Struct | The asynchronous invocation configuration. For more information, see asyncConfiguration. |
layers | No | String | The Alibaba Cloud Resource Name (ARN) of the layer. |
customContainerConfig
Parameter | Required | Type | Description |
---|---|---|---|
image | Yes | String | The URL of the image repository. |
command | No | String | The command to be run to start the container. |
args | No | String | The startup arguments of the container. |
accelerationType | No | String | Specifies whether to accelerate image pulling. Valid values:
|
instanceID | No | String | The ID of the Container Registry Enterprise Edition instance. If you pull an image from a Container Registry Enterprise Edition instance, you must specify the instance ID. The default resolved IP address of the domain name that you use to access the instance must be the VPC endpoint of the service. Alibaba Cloud DNS PrivateZone cannot be used for domain name resolution. |
instanceLifecycleConfig
Parameter | Required | Type | Description |
---|---|---|---|
preFreeze | No | Struct | The details of the PreFreeze function. |
preStop | No | Struct | The details of the PreStop function. |
Note The parameters contained in the
preStop
parameter are the same as those contained in the preFreeze
parameter. For more information about the parameters contained in the preFreeze
and preStop
parameters, see preFreeze or preStop.
preFreeze or preStop
Parameter | Required | Type | Description |
---|---|---|---|
handler | Yes | String | The handler of the PreFreeze or PreStop function. |
timeout | No | Number | The timeout period. |
asyncConfiguration
Parameter | Required | Type | Description |
---|---|---|---|
maxAsyncEventAgeInSeconds | No | Number | The maximum validity period of messages. Default value: 172800. Valid values: [1,2592000]. Unit: seconds. |
maxAsyncRetryAttempts | No | Number | The maximum number of retries allowed after an asynchronous invocation fails. Default value: 3. Valid values: [0,8]. |
statefulInvocation | No | Boolean | Specifies whether to enable the stateful asynchronous invocation mode. Valid values:
|
destination | No | Struct | The configuration structure of the destination for the asynchronous invocation. For more information, see destination. |
destination
Parameter | Required | Type | Description |
---|---|---|---|
onSuccess | No | String | The ARN of the destination for the asynchronous invocation if the asynchronous invocation is successful. |
onFailure | No | String | The ARN of the destination for the asynchronous invocation if the asynchronous invocation fails. |
triggers
The following table describes the parameters contained in the triggers field.
Parameter | Required | Type | Description |
---|---|---|---|
name | Yes | String | The name of the trigger. |
type | Yes | Enum | The type of the trigger. Valid values:
|
role | No | String | The ARN of the RAM role to be assumed to execute the function. The event source assumes this role to trigger the execution of the function. Make sure that the role has the permissions to invoke the function. |
qualifier | No | String | The version or alias of the service. |
sourceArn | No | String | The ARN of the event source for the trigger. |
config | Yes | Struct | The configuration of the trigger. The configuration varies with trigger types. |
OSS event trigger
Parameter | Required | Type | Description |
---|---|---|---|
bucketName | Yes | String | The name of the OSS bucket. |
events | Yes | List | The events that trigger the execution of the function in OSS. |
filter | Yes | Struct | The filter condition. Specify at least one filter condition. For more information, see filter. |
filter
Parameter | Required | Type | Description |
---|---|---|---|
key | No | Struct | The filter condition. For more information, see key. |
key
Parameter | Required | Type | Description |
---|---|---|---|
Prefix | No | String | The prefix. |
Suffix | No | String | The suffix. |
Log Service trigger
Parameter | Required | Type | Description |
---|---|---|---|
logConfig | Yes | String | The log configuration. For more information, see logConfig. |
jobConfig | Yes | List | The job configuration. For more information, see jobConfig. |
sourceConfig | Yes | Struct | The configuration of the data source. For more information, see sourceConfig. |
functionParameter | Yes | Struct | The event used by Log Service to trigger the execution of the function. By default,
this parameter is empty. In other words, the value of this parameter is {} . This parameter is passed into the function as the parameter that specifies the event
that triggers the execution of the function. This parameter can be of the OBJECT type.
|
enable | Yes | Boolean | Specifies whether to enable the trigger. |
logConfig
Parameter | Required | Type | Description |
---|---|---|---|
project | No | String | The name of the project in Log Service. |
logStore | No | String | The Logstore used to store function execution logs. |
jobConfig
Parameter | Required | Type | Description |
---|---|---|---|
maxRetryTime | No | String | The maximum number of retries allowed if an error occurs when Log Service triggers the execution of the function. Valid values: [0,100]. |
triggerInterval | No | String | The interval at which Log Service triggers the execution of the function. Valid values: [3,600]. Unit: seconds. |
sourceConfig
Parameter | Required | Type | Description |
---|---|---|---|
logstore | No | String | The Logstore name of the data source. The trigger regularly subscribes to data from the Logstore to Function Compute. |
Time trigger
Parameter | Required | Type | Description |
---|---|---|---|
cronExpression | Yes | String | The expression of the time trigger. CRON expressions and time zone expressions are supported. For more information, see the description of time expressions in the Configure a time trigger topic. |
enable | Yes | Boolean | Specifies whether to enable the trigger. Valid values:
|
payload | No | String | The input parameters. |
HTTP trigger
Parameter | Required | Type | Description |
---|---|---|---|
authType | Yes | String | The authentication type. Valid values: anonymous and function .
|
methods | Yes | List | The request methods supported by the HTTP trigger. Valid values: GET, POST, PUT, DELETE, and HEAD. |
MNS topic trigger
Parameter | Required | Type | Description |
---|---|---|---|
topicName | Yes | String | The name of the MNS topic trigger. |
region | No | List | The ID of the region where the MNS topic trigger resides. If this parameter is not specified, the default value is the ID of the region where the function resides. |
notifyContentFormat | No | String | The format of the parameter input event that is pushed to the function. Valid values: STREAM and JSON. |
notifyStrategy | No | String | The retry policy that is applied if an error occurs when MNS delivers a message to
the endpoint. Valid values:
|
filterTag | No | String | The tag used to filter messages in this subscription. Only messages to which the tag is added are pushed. The tag cannot exceed 16 characters in length. By default, messages are not filtered. In other words, this field is not specified by default. |
CDN event trigger
Parameter | Required | Type | Description |
---|---|---|---|
eventName | Yes | String | The CDN event that triggers the execution of the function. The event cannot be changed after the trigger is created. |
eventVersion | Yes | String | The version of the CDN event that triggers the execution of the function. The event version cannot be changed after the trigger is created. |
notes | Yes | String | The remarks. |
filter | Yes | Struct | The filter condition. Specify at least one filter condition. For more information, see filter. |
filter
Parameter | Required | Type | Description |
---|---|---|---|
domain | Yes | List | The URLs for filtering. |
Tablestore trigger
Parameter | Required | Type | Description |
---|---|---|---|
instanceName | Yes | String | The name of the Tablestore instance. |
tableName | Yes | String | The name of the table in Tablestore. |
The Tablestore trigger automatically triggers the execution of the function when data in Tablestore is updated.
customDomains
The following table describes the parameters contained in the customDomains field.
Parameter | Required | Type | Description |
---|---|---|---|
domainName | Yes | String | The domain name. If you set this parameter to auto , the system automatically assigns a domain name.
|
protocol | Yes | String | The protocol types supported by the domain name. Valid values:
|
routeConfigs | Yes | List | The configuration of the routing table. The routing table maps paths to functions when the functions are invoked by using the custom domain name. For more information, see routeConfigs. |
certConfig | No | Struct | The configuration of the certificate used for HTTPS. For more information, see certConfig. |
routeConfigs
Parameter | Required | Type | Description |
---|---|---|---|
path | Yes | String | The path. |
serviceName | No | String | The name of the service. |
functionName | No | String | The name of the function. |
qualifier | No | String | The version of the service. |
certConfig
Parameter | Required | Type | Description |
---|---|---|---|
certName | No | String | The name of the certificate. |
privateKey | No | String | The private key. |
certificate | No | String | The certificate. To configure a certificate chain, specify multiple certificates in sequence. |