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/qianfeng-fc-deploy-test-role'
        tracingConfig: Enable
        nasConfig:
          userId: 10003
          groupId: 10003
          mountPoints:
            - serverAddr: xxx.cn-qingdao.nas.aliyuncs.com
              nasDir: /qianfeng-fc-deploy-service
              fcDir: /mnt/auto
        vpcConfig:
          vpcId: xxx
          securityGroupId: xxx
          vswitchIds:
            - vsw-xxx
        logConfig:
          project: xxx
          logstore: xxx
          enableRequestMetrics: true
          enableInstanceMetrics: true
      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
        environmentVariables:
          key: 'value'
        initializationTimeout: 20
        initializer: index.initializer
        instanceConcurrency: 1
        instanceType: e1
        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
          config:
            authType: anonymous
            methods:
              - GET
        - name: timerTrigger
          type: timer
          config:
            cronExpression: '0 0 8 * * *'
            enable: true
            payload: 'awesome-fc'
        - name: ossTrigger
          type: oss
          role: xxx
          sourceArn: xxx
          config:
            bucketName: fassdemo
            events:
              - oss:ObjectCreated:*
              - oss:ObjectRemoved:DeleteObject
            filter:
              Key:
                Prefix: source/
                Suffix: .png
        - name: logTrigger
          type: log
          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
          role: xxx
          sourceArn: xxx
          config:
            topicName: test-topic
            region: cn-hangzhou
            notifyContentFormat: 'JSON'
            notifyStrategy: 'BACKOFF_RETRY'
        - name: cdnTrigger
          type: cdn_events
          role: xxx
          sourceArn: xxx
          config:
            eventName: LogFileCreated
            eventVersion: '1.0.0'
            notes: cdn events trigger test
            filter:
              domain: 
                - 'www.taobao.com'
                - 'www.tmall.com'
      customDomains:
        - domainName: auto
          protocol: HTTP
          routeConfigs:
            - path: /a
              serviceName: qianfeng-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 Yes Struct The details of the function. For more information, see function.
triggers Yes Struct The details of the triggers. For more information, see triggers.
customDomains Yes 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 Yes String The description of the service.
internetAccess No Boolean Specifies whether to allow functions in the specified service to access the Internet. Valid values:
  • true: allows functions in the specified service to access the Internet.
  • false: does not allow functions in the specified service to access the Internet.
tracingConfig No String Specifies whether to enable Tracing Analysis. Valid values:
  • Enable: enables Tracing Analysis.
  • Disable: disables Tracing Analysis.
role No This parameter supports the following two types:
  • String: simple configuration
  • Struct: detailed configuration
The Alibaba Cloud Resource Name (ARN) of the RAM role that is used to grant required permissions to Function Compute.
The following scenarios are included:
  • Sends function execution logs to your Logstore.
  • Generates a temporary key for a function to access other cloud resources when the function is executed.
For more information, see role.
logConfig No This parameter supports the following two types:
  • Enum: simple configuration
  • Struct: detailed configuration
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:
  • Enum: simple configuration
  • Struct: detailed configuration
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:
  • Enum: simple configuration
  • Struct: detailed configuration
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

The values of the role parameter of different types:
  • String: The value of the role parameter is a string in the format of acs:ram::xxx:role/qianfeng-fc-deploy-test-role.
  • Struct: The value of the role parameter is a structure. The following table describes the parameters contained in the role parameter.
    Parameter Required Type Description
    name Yes String The name of the RAM role.
    policies Yes List The policies attached to the RAM role.
    The following sample code shows the 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 logConfig parameter supports the following types:
  • String: The value of the logConfig parameter is a string. In this case, set this parameter to auto.
  • 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 No String The name of the Logstore in Log Service.
    project No String The name of the project in Log Service.
    enableRequestMetrics No Boolean Specifies whether to enable 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 collection of request-level metrics.
    • false: disables collection of request-level metrics.
    enableInstanceMetrics No Boolean Specifies whether to enable 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 collection of instance-level metrics.
    • false: disables collection of instance-level metrics.

vpcConfig

The vpcConfig parameter supports the following types:
  • String: The value of the vpcConfig parameter is a string. In this case, set this parameter to auto.
  • 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 No String The ID of the security group.
    vSwitchIds No List The IDs of one or more vSwitches.
    vpcId No 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 to auto.
  • 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 No 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 No String The address of the NAS server.
nasDir No String The directory of NAS.
fcDir No 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 specifications and usage modes topic.
runtime No String The runtime environment of the function. Valid values: nodejs6, nodejs8, nodejs10, nodejs12, python2.7, python3, java8, java11, php7.2, dotnetcore2.1, custom runtime, and custom container.
timeout No Number The timeout period for the execution of the function. Unit: seconds. Default value: 60. Valid values: 1 to 600. 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 runtime.
customContainerConfig No Struct The configuration of the custom container runtime. After you configure the custom container runtime, Function Compute can execute functions in a container created from a custom image. For more information, see customContainerConfig.
InstanceConcurrency No Number The maximum number of requests that a single instance can concurrently process.
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 Overview.
initializationTimeout No Number The timeout period for the execution of the initializer function. Unit: seconds. Default value: 3. Valid values: 1 to 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 Struct 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:
  • e1: elastic instance
  • c1: performance instance
instanceLifecycleConfig No Struct The extension functions. For more information, see instanceLifecycleConfig.
asyncConfiguration No Struct The asynchronous invocation configuration. For more information, see asyncConfiguration.

customContainerConfig

Parameter Required Type Description
image No String The URL of the container image repository.
command No String The command to be run to start the container.
args No String The startup arguments of the container.

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 and preStop.

preFreeze and preStop

Parameter Required Type Description
handler No String The handler of the PreFreeze or PreStop function.
timeout No Number The timeout period for the execution of the PreFreeze or PreStop function.

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 after an asynchronous invocation fails. Default value: 3. Valid values: [0,8].
statefulInvocation No Boolean Specifies whether to enable stateful asynchronous invocation. Valid values:
  • true: enables stateful asynchronous invocation.
  • false: disables stateful asynchronous invocation.
destination No Boolean The ARN 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.
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. 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 Struct 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.
triggerInterval No String The interval at which Log Service triggers the execution of the function.

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 CRON expression of the time trigger.
enable Yes List Specifies whether to enable the trigger. Valid values:
  • true: enables the trigger.
  • false: disables the trigger.
payload Yes Struct 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.
region No List The ID of the region where the MNS topic 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 List The retry policy that is applied if an error occurs when MNS delivers a message to the endpoint. Valid values:
  • BACKOFF_RETRY: backoff retry
  • EXPONENTIAL_DECAY_RETRY: exponential decay retry
filterTag No List 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 modified after it is created.
eventVersion Yes List The version of the CDN event that triggers the execution of the function. The event version cannot be modified after it 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.

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:
  • HTTP: Only HTTP is supported.
  • HTTPS: Only HTTPS is supported.
  • HTTP,HTTPS: Both HTTP and HTTPS are supported.
routeConfigs Yes List The configuration of the route table. The route 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.

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.