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 properties of the service, such as service authorizations and logging configurations.

Syntax

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

Properties

Name Type Required Editable Description Validity
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. The memory size ranges from 128 to 1536. The value can be increased in increments 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: second. Default value: 3. After this duration, Function Compute terminates the execution.

Valid values: 1 to 300.
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\u2019s used to run the 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 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"
        ]
      }
    }
  }
}