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 that is used by Function Compute to invoke the function. | None |
Runtime | String | Yes | Yes | The runtime environment of the function. | Valid values:
|
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 that is used by Function Compute to initialize the function. | The format is determined by the programming language. |
InitializationTimeout | Integer | No | Yes | The timeout period for Function Compute to initialize the 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: 128 to 1536.
Note The value must be a multiple of 64.
Unit: MB. Default value: 128. |
InstanceConcurrency | Integer | No | Yes | The number of requests that the function can process at a time. | Valid values: 1 to 100.
Note Python functions do not support this parameter.
|
EnvironmentVariables | Map | No | Yes | The environment variables configured for the function. | None |
Timeout | Integer | No | Yes | The timeout period for Function Compute to invoke the function. | Valid values: 1 to 300.
Unit: seconds. Default value: 3. |
Events | Map | No | Yes | The event that triggers the function. | For more information, visit Event source types. |
Response parameters
Fn::GetAtt
- FunctionId: the unique ID generated by the system for each function.
- ServiceName: the name of the service to which the function belongs.
- ARN: the Alibaba Cloud Resource Name (ARN) of the function.
- FunctionName: the name of the function.
Examples
JSON
format
{
"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 python2.7!",
"Runtime": "python2.7",
"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"
]
}
}
}
}
YAML
format
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 python2.7!
Runtime: python2.7
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