All Products
Search
Document Center

Resource Orchestration Service:Aliyun::Serverless::Function

Last Updated:Jan 10, 2025

Aliyun::Serverless::Function is used to create a function in Function Compute.

Syntax

{
 "Type": "Aliyun::Serverless::Function",
 "Properties": {
  "Handler": String,
  "Runtime": String,
  "CodeUri": String,
  "Initializer": String,
  "Description": String,
  "MemorySize": Integer,
  "Timeout": Integer,
  "InitializationTimeout": Integer,
  "EnvironmentVariables": Map,
  "InstanceConcurrency": Integer,
 },
   "Events": Map
}

Properties

Property

Type

Required

Editable

Description

Constraint

Handler

String

Yes

Yes

The handler of the function.

None.

Runtime

String

Yes

Yes

The runtime of the function.

Valid values:

  • nodejs6

  • nodejs8

  • nodejs10

  • nodejs12

  • python3

  • java8

  • php7.2

  • dotnetcore2.1

CodeUri

String

Yes

Yes

The storage location of the code.

The code can be stored in an Object Storage Service (OSS) bucket or the directory of the project.

Initializer

String

No

Yes

The handler of the initializer function.

The format of the value varies based on the programming language.

InitializationTimeout

Integer

No

Yes

The timeout period for the execution of the initializer function.

Valid values: 1 to 300.

Unit: seconds.

Default value: 3.

Description

String

No

Yes

The description of the function.

None.

MemorySize

Integer

No

Yes

The memory that is required to execute the function.

Valid values: multiples of 64 that range from 128 to 1536.

Note

Unit: MB.

Default value: 128.

InstanceConcurrency

Integer

No

Yes

The instance concurrency value.

Valid values: 1 to 100.

Note

Python functions do not support this property.

EnvironmentVariables

Map

No

Yes

The environment variables that you want to configure for the function.

None.

Timeout

Integer

No

Yes

The timeout period for the execution of the function.

Valid values: 1 to 300.

Unit: seconds.

Default value: 3.

Events

Map

No

Yes

The events that trigger the function.

For more information, see Event source types.

Return values

Fn::GetAtt

  • FunctionId: the unique ID that is generated by the system for the function.

  • ServiceName: the name of the service in Function Compute.

  • ARN: the Alibaba Cloud Resource Name (ARN) of the function.

  • FunctionName: the name of the function.

Examples

ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Parameters:
 CodeUri:
  Type: String
Resources:
 MyService:
  Type: 'Aliyun::Serverless::Service'
  Properties: {}
  MyFunction:
   Type: 'Aliyun::Serverless::Function'
   Properties:
    Handler: index.handler
    CodeUri:
     Ref: CodeUri
    Description: Hello world with python3!
    Runtime: python3
    Timeout: 300
Outputs:
 MyServiceId:
  Value:
   'Fn::GetAtt':
    - MyService
    - ServiceId
 ServiceName:
  Value:
   'Fn::GetAtt':
    - MyService
    - ServiceName
 FunctionName:
  Value:
   'Fn::GetAtt':
    - MyServiceMyFunction
    - FunctionName
 FunctionId:
  Value:
   'Fn::GetAtt':
    - MyServiceMyFunction
    - FunctionId
 ARN:
  Value:
   'Fn::GetAtt':
    - MyServiceMyFunction
    - ARN
 FunctionServiceName:
  Value:
   'Fn::GetAtt':
    - MyServiceMyFunction
    - ServiceName
{
 "ROSTemplateFormatVersion": "2015-09-01",
 "Transform": "Aliyun::Serverless-2018-04-03",
 "Parameters": {
  "CodeUri": {
   "Type": "String"
  }
 },
 "Resources": {
  "MyService": {
   "Type": "Aliyun::Serverless::Service",
   "Properties": {},
   "MyFunction": {
    "Type": "Aliyun::Serverless::Function",
    "Properties": {
     "Handler": "index.handler",
     "CodeUri": {
      "Ref": "CodeUri"
     },
     "Description": "Hello world with python3!",
     "Runtime": "python3",
     "Timeout": 300
    }
   }
  }
 },
 "Outputs": {
  "MyServiceId": {
   "Value": {
    "Fn::GetAtt": [
     "MyService",
     "ServiceId"
    ]
   }
  },
  "ServiceName": {
   "Value": {
    "Fn::GetAtt": [
     "MyService",
     "ServiceName"
    ]
   }
  },
  "FunctionName": {
   "Value": {
    "Fn::GetAtt": [
     "MyServiceMyFunction",
     "FunctionName"
    ]
   }
  },
  "FunctionId": {
   "Value": {
    "Fn::GetAtt": [
     "MyServiceMyFunction",
     "FunctionId"
    ]
   }
  },
  "ARN": {
   "Value": {
    "Fn::GetAtt": [
     "MyServiceMyFunction",
     "ARN"
    ]
   }
  },
  "FunctionServiceName": {
   "Value": {
    "Fn::GetAtt": [
     "MyServiceMyFunction",
     "ServiceName"
    ]
   }
  }
 }
}