Publishing a Function Version
Function
This API is used to publish a function version.
Calling Method
For details, see Calling APIs.
Authorization Information
Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions. For details about the required permissions, see Permissions Policies and Supported Actions.
URI
POST /v2/{project_id}/fgs/functions/{function_urn}/versions
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Parameter description: Project ID. For details, see Obtaining a Project ID. Constraints: None Value range: 32 characters, including letters and digits. Default value: None |
| function_urn | Yes | String | Parameter description: URN of the function. For details, see Function Model. Constraints: None Value range: Only letters, digits, underscores (_), hyphens (-), and colons (:) are allowed. Default value: None |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Parameter description: User token. The token can be obtained by calling the IAM API. The value of X-Subject-Token in the response header is the user token. Constraints: None Value range: None Default value: None |
| Content-Type | Yes | String | Parameter description: Specifies the type (or format) of the message body. Constraints: None Value range: Only application/json is supported. Default value: application/json |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| digest | No | String | Definition MD5 key. Constraints None Range None Default Value None |
| version | No | String | Definition Function version. Constraints The value can contain only letters, digits, hyphens (-), underscores (_), and periods (.), and must start and end with a letter or digit. Range The value can contain a maximum of 42 characters. Default Value The version number is generated based on the time by default, for example, v20180116-202722. |
| description | No | String | Definition Version description. Constraints None Range Max. 512 characters. Default Value None |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| func_urn | String | Definition Function URN. Range None |
| func_name | String | Definition Function name Range None |
| domain_id | String | Definition Domain name ID. Range None |
| namespace | String | Definition Project ID. Range None |
| project_name | String | Definition Project name. Range None |
| package | String | Definition Group to which the function belongs. This field is defined to group functions. Range None |
| runtime | String | Parameter description: Runtime of a FunctionGraph function, that is, the function execution environment. Range Custom image-based functions |
| timeout | Integer | Definition Execution timeout allowed for a function. Range 3–259200 seconds |
| handler | String | Definition Handler Range It is in the format of "xx.xx" and must contain a period (.). The handler of a custom image function is -. For example, for Node.js function myfunction.handler, the file name is myfunction.js, and the handler function is handler. Can contain a maximum of 128 characters. |
| memory_size | Integer | Parameter description: Memory (MB) consumed by the function. Range |
| cpu | Integer | Definition CPU resources of a function. Unit: millicore (1 core = 1000 millicores). Range The value of this field is proportional to that of MemorySize. By default, 100 CPU millicores are required for 128 MB memory. |
| code_type | String | Definition Function code type Range inline: inline code zip: ZIP file obs: function code stored in an OBS bucket jar: JAR file, mainly for Java functions Custom-Image-Swr: The function code comes from the SWR custom image. |
| code_url | String | Definition If CodeType is set to obs, enter the OBS URL of the function code package. If CodeType is not set to obs, leave this parameter blank. Range None |
| code_filename | String | Definition Name of a function file. This parameter is mandatory only when CodeType is set to jar or zip. Range None |
| code_size | Long | Definition Code size in bytes. Range None |
| user_data | String | Definition Name/Value information defined for the function. These are parameters used in the function. For example, if a function needs to access a host, you can set a custom parameter as follows: Host={host_ip} Range The total length cannot exceed 4 KB. |
| encrypted_user_data | String | Definition Name/value information to be encrypted. Range Message structure, which is a JSON string. |
| digest | String | Definition SHA512 hash value of function code, which is used to determine whether the function is changed. Range None |
| version | String | Definition Function version, which is automatically generated by the system. The version name is in the format of "vYYYYMMDD-HHMMSS" (v+year/month/day-hour/minute/second). Range None |
| image_name | String | Definition Internal identifier of a function version. Range None |
| xrole | String | Definition Configuration agency. You need to create an agency on the IAM console. This field is mandatory when a function needs to access other services. After specifying a function configuration agency, you can use the context method in the function handler to obtain a token, an AK, and an SK for accessing other cloud services. No agency is required if FunctionGraph does not access any cloud services. Range None |
| app_xrole | String | Definition Execution agency. You can optimize performance by configuring a separate agency for function execution, otherwise, the same agency is used for both execution and configuration. Range None |
| description | String | Definition Description of the function. Range None |
| version_description | String | Definition Description of the function version. Range None |
| last_modified | String | Definition Time when the function was last updated. Range None |
| func_vpc | FuncVpc object | VPC configuration. An agency with VPC permissions must be configured for the function. |
| mount_config | MountConfig object | Mounting configuration. |
| strategy_config | StrategyConfig object | Parameter description: Function policy configuration. |
| status | Integer | Definition Function status Range 0: enabled -1: disabled |
| dependencies | Array of Dependency objects | Definition Dependency packages. |
| initializer_handler | String | Definition Initializer of the function in the format of "xx.xx". It must contain a period (.). ". This parameter is mandatory when the initialization function is configured. For example, for Node.js function myfunction.initializer, the file name is myfunction.js, and the initialization function is initializer. Range None |
| initializer_timeout | Integer | Definition Maximum duration the function can be initialized. Value range: 1s–300s. This parameter is mandatory when the initialization function is configured. Range None |
| pre_stop_handler | String | Definition The pre-stop handler of a function. The value must contain a period (.) in the format of xx.xx. ". For example, for Node.js function myfunction.pre_stop_handler, the file name is myfunction.js, and the initialization function is pre_stop_handler. Range None |
| pre_stop_timeout | Integer | Definition Initialization timeout interval, in seconds. If the timeout interval is reached, the function will be forcibly stopped. Range The value ranges from 1 to 90. |
| enterprise_project_id | String | Definition Enterprise project ID. This parameter is mandatory if you create a function as an enterprise user. Range None |
| long_time | Boolean | Definition Whether to allow a long timeout. Range None |
| log_group_id | String | Definition Log group ID. Range None |
| log_stream_id | String | Definition Log stream ID. Range None |
| type | String | Definition Function type. Range v1: discarded version v2: official version |
| enable_dynamic_memory | Boolean | Definition Whether to enable dynamic memory allocation. Range None |
| function_async_config | FunctionAsyncConfig object | Definition Asynchronous Execution Notification |
| Parameter | Type | Description |
|---|---|---|
| domain_id | String | Parameter description: Tenant account ID. Value range: None |
| namespace | String | Parameter description: Project ID. Value range: None |
| vpc_name | String | Definition: VPC name Value range: None |
| vpc_id | String | Parameter description: VPC ID. Value range: None |
| subnet_name | String | Parameter description: Subnet name. Value range: None |
| subnet_id | String | Parameter description: Subnet ID. Value range: None |
| cidr | String | Parameter description: Subnet mask. Value range: None |
| gateway | String | Parameter description: Gateway. Value range: None |
| security_groups | Array of strings | Parameter description: Security Group Value range: Character string list |
| is_safety | Boolean | Definition Whether to enable secure access. When secure access is enabled, you need to configure the VPCEP network to establish a secure VPC connection to private domain names. Once enabled, this feature cannot be disabled. Range |
| Parameter | Type | Description |
|---|---|---|
| mount_user | MountUser object | User information. |
| func_mounts | Array of FuncMount objects | Parameter description: Mounted resources. Value range: None |
| Parameter | Type | Description |
|---|---|---|
| user_id | Integer | Parameter description: User ID. Value range: An integer ranging from -1 to 65534 |
| user_group_id | Integer | Parameter description: Group ID Value range: An integer ranging from -1 to 65534 |
| Parameter | Type | Description |
|---|---|---|
| mount_type | String | Definition Mount type. This parameter is mandatory when func_mounts is not empty. Range |
| mount_resource | String | Parameter description: ID of the mounted resource (cloud service ID). This parameter is mandatory when func_mounts is not empty. Value range: None |
| mount_share_path | String | Parameter description: Remote mount path. For example, 192.168.0.12:/data. This parameter is mandatory if mount_type is set to ecs. Value range: Shared path opened by the ECS |
| local_mount_path | String | Parameter description: Function access path. This parameter is mandatory when func_mounts is not empty. Value range: Mount directory in the function container. The directory is generally a two-layer structure. |
| Parameter | Type | Description |
|---|---|---|
| concurrency | Integer | Parameter description: Specifies the maximum number of instances for a function. The value -1 indicates that the number of instances is not limited. Value range: v1: 0 and -1 v2: [–1, 1000] |
| concurrent_num | Integer | Parameter description: Specifies the number of concurrent requests per instance. This parameter is supported in v2. Value range: [1, 1000] |
| Parameter | Type | Description |
|---|---|---|
| id | String | Parameter description: Dependency version ID. Value range: None |
| owner | String | Parameter description: Domain ID of the dependency owner. Value range: None |
| link | String | Parameter description: URL of the dependency on OBS. Value range: OBS link |
| runtime | String | Parameter description: Runtime of a function. Value range: Custom Custom image-based functions |
| etag | String | Parameter description: MD5 value of a dependency. Value range: None |
| size | Long | Parameter description: Dependency size. Value range: None |
| name | String | Parameter description: Name of a dependency package. Value range: None |
| description | String | Parameter description: Dependency description. Value range: None |
| file_name | String | Parameter description: File name of a dependency package (ZIP). Value range: None |
| version | Long | Parameter description: Dependency version ID. Value range: None |
| dep_id | String | Parameter description: Dependency ID. Value range: None |
| last_modified | String | Parameter description: Time when the function was last updated. Value range: None |
| Parameter | Type | Description |
|---|---|---|
| max_async_event_age_in_seconds | Integer | Parameter description: Maximum duration for which a message can survive. Range 60 to 86400 Unit: second. |
| max_async_retry_attempts | Integer | Parameter description: Maximum number of retry attempts to be made if asynchronous invocation fails. Default value: 3. Range Value range: 0–8. |
| destination_config | FuncAsyncDestinationConfig object | Parameter description: Asynchronous invocation target. Range: None |
| created_time | String | Parameter description: Time when asynchronous execution notification was configured. Range: None |
| last_modified | String | Parameter description: Time when the asynchronous execution notification settings were last modified. Range: None |
| Parameter | Type | Description |
|---|---|---|
| on_success | FuncDestinationConfig object | Parameter description: Target to be invoked when a function is successfully executed. Range: None |
| on_failure | FuncDestinationConfig object | Parameter description: Target to be invoked when a function fails to be executed due to a system error or an internal error. Range: None |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Error code. |
| error_msg | String | Error message. |
Status code: 401
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Error code. |
| error_msg | String | Error message. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Error code. |
| error_msg | String | Error message. |
Status code: 404
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Error code. |
| error_msg | String | Error message. |
Status code: 500
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Error code. |
| error_msg | String | Error message. |
Example Requests
Publish a function version.
POST https://{Endpoint}/v2/{project_id}/fgs/functions/{function_urn}/versions
{
"version" : "v1",
"description" : "v1"
} Example Responses
Status code: 200
{
"func_urn" : "urn:fss:xxxxxxxxx:7aad83af3e8d42e99ac194e8419e2c9b:function:default:test",
"func_name" : "test",
"domain_id" : "14ee2e3501124efcbca7998baa24xxxx",
"namespace" : "46b6f338fc3445b8846c71dfb1fbxxxx",
"project_name" : "xxxxx",
"package" : "default",
"runtime" : "Node.js6.10",
"timeout" : 3,
"handler" : "test.handler",
"memory_size" : 128,
"cpu" : 100,
"code_type" : "inline",
"code_filename" : "inline.js",
"code_size" : 272,
"digest" : "faa825575c45437cddd4e369bea69893bcbe195d478178462ad90984fe72993f3f59d15f41c5373f807f3e05fb9af322c55dabeb16565c386e402413458e6068",
"version" : "v20191025-153727",
"image_name" : "latest-191025153727@zehht",
"last_modified" : "2019-10-25 15:37:27",
"status" : 0,
"strategy_config" : {
"concurrency" : 0
}
} Status code: 404
{
"error_code" : "FSS.1051",
"error_msg" : "Not found the function"
} SDK Sample Code
The SDK sample code is as follows.
Java
Publish a function version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.functiongraph.v2.region.FunctionGraphRegion; import com.huaweicloud.sdk.functiongraph.v2.*; import com.huaweicloud.sdk.functiongraph.v2.model.*; public class CreateFunctionVersionSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); FunctionGraphClient client = FunctionGraphClient.newBuilder() .withCredential(auth) .withRegion(FunctionGraphRegion.valueOf("<YOUR REGION>")) .build(); CreateFunctionVersionRequest request = new CreateFunctionVersionRequest(); request.withFunctionUrn("{function_urn}"); CreateFunctionVersionRequestBody body = new CreateFunctionVersionRequestBody(); body.withDescription("v1"); body.withVersion("v1"); request.withBody(body); try { CreateFunctionVersionResponse response = client.createFunctionVersion(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
Python
Publish a function version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkfunctiongraph.v2.region.functiongraph_region import FunctionGraphRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkfunctiongraph.v2 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = FunctionGraphClient.new_builder() \ .with_credentials(credentials) \ .with_region(FunctionGraphRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreateFunctionVersionRequest() request.function_urn = "{function_urn}" request.body = CreateFunctionVersionRequestBody( description="v1", version="v1" ) response = client.create_function_version(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
Go
Publish a function version.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" functiongraph "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/functiongraph/v2/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth, err := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). SafeBuild() if err != nil { fmt.Println(err) return } hcClient, err := functiongraph.FunctionGraphClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). SafeBuild() if err != nil { fmt.Println(err) return } client := functiongraph.NewFunctionGraphClient(hcClient) request := &model.CreateFunctionVersionRequest{} request.FunctionUrn = "{function_urn}" descriptionCreateFunctionVersionRequestBody:= "v1" versionCreateFunctionVersionRequestBody:= "v1" request.Body = &model.CreateFunctionVersionRequestBody{ Description: &descriptionCreateFunctionVersionRequestBody, Version: &versionCreateFunctionVersionRequestBody, } response, err := client.CreateFunctionVersion(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
More
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
| Status Code | Description |
|---|---|
| 200 | OK |
| 400 | Bad request. |
| 401 | Unauthorized. |
| 403 | Forbidden. |
| 404 | Not found. |
| 500 | Internal server error. |
Error Codes
See Error Codes.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot