Function Compute is a major upgraded version of Function Compute. In Function Compute 3.0, various features related to function management, function execution engines, custom domain names, permission management, and auto scaling rules are updated to provide better user experience. This topic describes feature changes in Function Compute 3.0 and how Function Compute 3.0 is compatible with original services and functions.
Feature updates in Function Compute 3.0
The following features are updated in Function Compute 3.0:
Function management
Services are no longer used in Function Compute. Functions become first-level entities. Roles, logs, and virtual private clouds (VPCs) are configured at the function level.
Versions and aliases are configured at the function level. You can use versions and aliases to perform version management on functions.
For more information, see Function management.
Function execution engines
The handler signatures of HTTP requests and event requests are unified. For more information, see Behaviors of HTTP triggers.
Standard runtimes of Function Compute no longer support the instance concurrency feature. Instances that run in custom runtimes still support the concurrency feature.
PreFreeze hooks are no longer supported in the lifecycle management of function instances.
Custom domain names
Custom domain names no longer depend on HTTP triggers and can be directly redirected to functions.
Permission management
Service-linked roles are supported to simplify function authorization. For more information, see Service-linked roles.
Auto scaling rules
The auto scaling feature of provisioned instances is incorporated into the concurrency management of instances. You can limit the total concurrency of provisioned instances and on-demand instances.
The configurations of original services and functions remain unchanged. Original functions can still be invoked as expected. For example, the instance concurrency that you configured for a function in Function Compute 2.0 is still effective in Function Compute 3.0. However, functions that are created in standard runtimes of Function Compute 3.0 no longer support the instance concurrency feature. For information about the compatibility of Function Compute 3.0 with original services and functions, see Compatibility with original services and functions.
Function management
In Function Compute, you can create functions without the need to create services. The original service-level configurations, such as roles, logging, and VPCs, are now configured in functions. The following sample code provides an example of function configurations in Function Compute SDK for Go:
resp, err := client.CreateFunction(
new(fc.CreateFunctionRequest).
SetBody(&fc.CreateFunctionInput{
FunctionName: &funcName,
Runtime: tea.String("nodejs12"),
Handler: tea.String("index.handler"),
MemorySize: tea.Int32(128),
Role: tea.String("role-arn"),
VpcConfig: &fc.VPCConfig{
VpcId: tea.String("vpc-id"),
VSwitchIds: []*string{tea.String("vsw-id")},
SecurityGroupId: tea.String("sg-id"),
},
Code: new(fc.InputCodeLocation).SetZipFile(fx.GetCodeZipBase64()),
}))
event := "my event"
resp, err = client.InvokeFunction(&funcName,
new(fc.InvokeFunctionRequest).SetBody(strings.NewReader(event)))
body, err := ioutil.ReadAll(resp.Body)
The following sample code provides an example on how to publish a version and create an alias for a function in Function Compute SDK for Go:
resp, err := client.PublishFunctionVersion(&funcName,
new(fc.PublishFunctionVersionRequest).SetBody(&fc.PublishVersionInput{
Description: tea.String("version desc"),
}))
aliasName := "my-alias"
routingConfig := map[string]*float32{
"2": tea.Float32(float32(0.05)),
}
resp, err := client.CreateAlias(&funcName, new(fc.CreateAliasRequest).
SetBody(&fc.CreateAliasInput{
AliasName: &aliasName,
VersionId: tea.String("1"),
AdditionalVersionWeight: routingConfig,
}))
Behaviors of HTTP triggers
In Function Compute 3.0, handlers for event requests and HTTP requests are unified. The following sample code provides an example in Python:
def handler(event, context):
return 'hello fc'
Function Compute converts requests that access functions by using the URLs of HTTP triggers or custom domain names into events and converts function responses into HTTP responses.
The following sample code provides an example event request:
{
"version": "v1",
"rawPath": "/my/path",
"httpMethod": "POST",
"headers": {
"header1": "value1,value2",
"header2": "value2"
},
"queryParameters": {
"param1": "value1,value2",
"param2": "value2"
},
"body": "hello from client",
"isBase64Encoded": false,
"requestContext": {
"accountId": "12345678",
"domainName": "my-domain.com",
"domainPrefix": "prefix",
"requestId": "abcd-efgh",
"time": "2023-09-01T14:17:23+08:00",
"timeEpoch": 1693549043255,
"http": {
"method": "GET",
"path": "/my/path",
"protocol": "http",
"sourceIP": "39.40.41.42",
"userAgent": "go-sdk/1.0"
}
}
}
The following sample code provides an example HTTP response:
def handler(event, context):
return {
'body': 'hello FC',
'headers': {
'my-custom-header': 'foo'
},
'statusCode': 400
}
The following code shows the converted HTTP response of the preceding code:
HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
My-Custom-Header: foo
X-Fc-Request-Id: 64e866c9-69902fbc525fd10989e7299c
Date: Fri, 25 Aug 2023 10:18:06 GMT
Content-Length: 8
hello FC
For information about the format conversion of requests and responses, see Overview.
Service-linked roles
When you use specific features provided by Function Compute, such as logging, VPC, and asynchronous invocation, Function Compute needs to access other Alibaba Cloud services. For example, when you configure the logging feature for a function, you must grant Function Compute the write permissions on a Simple Log Service Logstore before Function Compute can write logs to the Logstore. In earlier versions, the write permissions on Simple Log Service Logstores are configured by using service roles. Service roles are assumed by Function Compute and function code to access other Alibaba Cloud services. This may cause excessive permissions to be granted to service roles.
In Function Compute 3.0, service-linked roles are supported. You can use service-linked roles to authorize Function Compute to access other Alibaba Cloud services. If your code needs to access other Alibaba Cloud services, you can use function roles to implement authorization. Function Compute also allows you to manage permissions of function roles in a fine-grained manner based on your business requirements.
After you create the service-linked role, functions that you create in Function Compute 3.0 can automatically assume the service-linked role. You can use specific features, such as logging, VPC, and asynchronous invocation, on functions without the need to configure roles for the functions.
Compatibility with original services and functions
Function Compute 3.0 provides a new set of API operations and a new console GUI, which are compatible with original services and functions. The following table describes the compatibility rules and provides examples for better understanding. In the examples, you have created the service s1 that contains the function f1 and function f2 in Function Compute 2.0. The version 1, version 2, and alias prod were created for the service s1 in Function Compute 2.0.
Category | Compatibility rule | Example |
Service configurations | Original services and functions are all converted into functions in Function Compute 3.0 in the The original service configurations, such as service roles, logging, and VPCs, are converted into function configurations. | In Function Compute 3.0, the original functions are converted to the function |
The configuration updates of a function in a service do not affect other functions in the service. | If you update the VPC configurations of the function | |
If you call an API operation of Function Compute 2.0 to update service configurations, the corresponding configurations of all functions in the service are updated. | If you update the VPC configurations of the service s1 in Function Compute 2.0, the VPC configurations of both the function | |
Version and aliases | The original service versions and aliases are converted into function versions and aliases. | In Function Compute 3.0, the function |
New versions of a function take effect on the original service to which the function belongs and other functions in the service. | If you publish the version 3 for the function | |
New aliases of a function take effect on the service to which the function belongs and other functions in the service. | If you create the alias test for the function | |
You cannot delete versions or aliases of a converted function in Function Compute 3.0 because the versions and aliases are shared by the service and other functions in the service. | If you attempt to delete the version 3 of the function | |
Updates of aliases of a function do not affect other functions in the service. | If you update the alias prod for the function | |
If you call an API operations of Function Compute 2.0 to update service aliases, the aliases of all functions in the service are updated. | If you update the alias prod for the service s1 and change the version to which the alias prod points from the version 1 to the version 2, the alias prod of the function |
After you perform operations on an original function in the Function Compute 3.0 console, the function has independent service-level configurations. Subsequent updates performed in the Function Compute 3.0 console on the function affect only the function itself. If you update service-level configurations of a function in the Function Compute 2.0 console, the corresponding configurations of all functions in the service are updated.