ALIYUN::FC::Function is used to create a function. A function is an object that the system uses for scheduling and execution. Functions must be associated with services. All functions of a service share the same properties as the service, such as service authorizations and logging configurations.

Syntax

{
  "Type": "ALIYUN::FC::Function",
  "Properties": {
    "Code": Map,
    "FunctionName": String,
    "ServiceName": String,
    "MemorySize": Integer,
    "EnvironmentVariables": Map,
    "Initializer": String,
    "Handler": String,
    "Timeout": Integer,
    "InitializationTimeout": Integer,
    "Runtime": String,
    "Description": String
  }
}

Properties

Name Type Required Editable Description Validity
Initializer String No Yes The entry point for Function Compute to initialize the function to be created. The format is determined by the programming language.
InitializationTimeout Integer No Yes The timeout period that is specified for the function initialization request. Unit: seconds. Valid values: 1 to 300. Default value: 3. If the function is not initialized within the specified period, Function Compute terminates the execution.
Code Map Yes Yes The code that contains the function implementation. The code must be packaged into a ZIP file. None
Description String No Yes The description of the function. None
ServiceName String Yes No The name of the service. The name must be 1 to 128 characters in length.
MemorySize Integer No Yes The memory size of the function. Unit: MB. Valid values: 128 to 1536. The value must be a multiple of 64.
EnvironmentVariables Map No Yes The environment variables configured for the function. None
Handler String Yes Yes The entry point for Function Compute to execute the function. The format is determined by the programming language.
Timeout Integer No Yes The timeout period that is specified for the function execution request. Unit: seconds. Valid values: 1 to 300. Default value: 3. If the function is not executed within the specified period, Function Compute terminates the execution.
Runtime String Yes Yes The runtime environment of the function. Valid values: nodejs6, nodejs8, python2.7, python3, and java8.
FunctionName String Yes No The name of the function. None

Code syntax

"Code": {
  "OssBucketName": String,
  "OssObjectName": String,
  "ZipFile": String,
  "SourceCode": String
}

Code properties

Name Type Required Editable Description Validity
OssBucketName String No Yes The name of the bucket where the function code package is stored. None
OssObjectName String No Yes The name of the object where the function code package is stored. None
ZipFile String No Yes The Base64-encoded ZIP file to be uploaded in the request body. None
SourceCode String No Yes The source code of the function. Node.js, PHP, and Python code is supported. The code can be up to 4,096 characters in length. ROS will write the value of this parameter into a UTF-8 encoded file named index. When the ZipFile, SourceCode, and OssBucketName&OssObjectName parameters are specified together, the three parameters are in descending order of priority.

Response parameters

Fn::GetAtt

FunctionId: the unique ID generated by the system for each function.

Examples

JSON format

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Resources": {
    "Function": {
      "Type": "ALIYUN::FC::Function",
      "Properties": {
        "Code": {
          "Ref": "Code"
        },
        "Description": {
          "Ref": "Description"
        },
        "ServiceName": {
          "Ref": "ServiceName"
        },
        "MemorySize": {
          "Ref": "MemorySize"
        },
        "EnvironmentVariables": {
          "Ref": "EnvironmentVariables"
        },
        "Handler": {
          "Ref": "Handler"
        },
        "Timeout": {
          "Ref": "Timeout"
        },
        "Runtime": {
          "Ref": "Runtime"
        },
        "FunctionName": {
          "Ref": "FunctionName"
        }
      }
    }
  },
  "Parameters": {
    "Code": {
      "Type": "Json",
      "Description": "The code that contains the function implementation."
    },
    "Description": {
      "Type": "String",
      "Description": "Function description"
    },
    "ServiceName": {
      "MinLength": 1,
      "Type": "String",
      "Description": "Service name",
      "MaxLength": 128
    },
    "MemorySize": {
      "Default": 128,
      "Type": "Number",
      "Description": "The amount of memory that\u2019s used to run function, in MB. Function Compute uses this value to allocate CPU resources proportionally. Defaults to 128 MB. It can be multiple of 64 MB and between 128 MB and 3072 MB.",
      "MaxValue": 1536,
      "MinValue": 128
    },
    "EnvironmentVariables": {
      "Type": "Json",
      "Description": "The environment variable set for the function, you can get the value of the environment variable in the function."
    },
    "Handler": {
      "Type": "String",
      "Description": "The function execution entry point."
    },
    "Timeout": {
      "Default": 3,
      "Type": "Number",
      "Description": "The maximum time duration a function can run, in seconds. After which Function Compute terminates the execution. Defaults to 3 seconds, and can be between 1 to 300 seconds.",
      "MaxValue": 300,
      "MinValue": 1
    },
    "Runtime": {
      "Type": "String",
      "Description": "The function runtime environment. Supporting nodejs6, nodejs8, python2.7, python3, java8",
      "AllowedValues": [
        "nodejs6",
        "nodejs8",
        "python2.7",
        "python3",
        "java8"
      ]
    },
    "FunctionName": {
      "Type": "String",
      "Description": "Function name"
    }
  },
  "Outputs": {
    "FunctionId": {
      "Description": "The function ID",
      "Value": {
        "Fn::GetAtt": [
          "Function",
          "FunctionId"
        ]
      }
    }
  }
}