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 used. None
InitializationTimeout Integer No Yes The timeout period for function initialization. Unit: seconds. Valid values: 1 to 5. Default value: 3. When this period expires, Function Compute terminates the execution. None
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 to which the function belongs. 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 of this parameter must be a multiple of 64.
EnvironmentVariables Map No Yes

The environment variables configured for the function. You can obtain the values of the environment variables in the function.

None
Handler String Yes Yes

The entry point for Function Compute to run the function. The format is determined by the programming language used.

None
Timeout Integer No Yes

The timeout period for function execution. Unit: seconds. Default value: 3. When this period expires, Function Compute terminates the execution.

Valid values: 1 to 5
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
}

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

Response parameters

Fn::GetAtt

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

Examples

{
  "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 is used to run the function, in MB. Function Compute uses this value to allocate CPU resources proportionally. Defaults to 128 MB. It must be a multiple of 64 MB and between 128 MB and 1536 MB.",
      "MaxValue": 1536,
      "MinValue": 128
    },
    "EnvironmentVariables": {
      "Type": "Json",
      "Description": "The environment variables set for the function. You can obtain the values of the environment variables in the function."
    },
    "Handler": {
      "Type": "String",
      "Description": "The function execution entry point."
    },
    "Timeout": {
      "Default": 3,
      "Type": "Number",
      "Description": "The maximum duration a function can run, in seconds. After the duration, Function Compute terminates the execution. Defaults to 3 seconds, and can be between 1 to 5 seconds.",
      "MaxValue": 5,
      "MinValue": 1
    },
    "Runtime": {
      "Type": "String",
      "Description": "The function runtime environment. Valid values: nodejs6, nodejs8, python2.7, python3, and 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"
        ]
      }
    }
  }
}