Aliyun::Serverless::Function

Updated at:

Creates a Function Compute (FC) function.

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 name

Type

Required

Update allowed

Description

Constraints

Handler

String

Yes

Yes

The entry point of the function.

None

Runtime

String

Yes

Yes

The runtime environment of the function.

Valid values:

  • nodejs6

  • nodejs8

  • nodejs10

  • nodejs12

  • python3

  • java8

  • php7.2

  • dotnetcore2.1

CodeUri

String

Yes

Yes

The code location.

An OSS address or a code path in the project.

Initializer

String

No

Yes

The entry point of the initializer function.

The format varies by runtime language.

InitializationTimeout

Integer

No

Yes

The execution timeout of the initializer function.

Value range: 1 to 300.

Unit: seconds.

Default value: 3.

Description

String

No

Yes

The description of the function.

None

MemorySize

Integer

No

Yes

The memory allocated to the function.

Value range: 128 to 1536.

Note

The value must be a multiple of 64.

Unit: MB.

Default value: 128.

InstanceConcurrency

Integer

No

Yes

The number of concurrent requests allowed per instance.

Value range: 1 to 100.

Note

This parameter is not supported for Python function instances.

EnvironmentVariables

Map

No

Yes

The environment variables for the function.

None

Timeout

Integer

No

Yes

The execution timeout of the function.

Value range: 1 to 300.

Unit: seconds.

Default value: 3.

Events

Map

No

Yes

The events that trigger the function.

For more information, see Event source.

Return values

Fn::GetAtt

  • FunctionId: The unique ID generated for the function.

  • ServiceName: The name of the service.

  • 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"
    ]
   }
  }
 }
}