Help Center/ FunctionGraph/ API Reference/ APIs/ Versions and Aliases/ Creating an Alias for a Function Version
Updated on 2026-10-27 GMT+08:00

Creating an Alias for a Function Version

Function

This API is used to create an alias for 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}/aliases

Table 1 Path Parameters

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

Table 2 Request header 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

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Parameter description:

Alias.

Constraints:

The value can contain letters, digits, underscores (_), and hyphens (-). It must start with a letter and end with a letter or digit.

Value range:

The value cannot exceed 64 characters.

Default value:

None

version

Yes

String

Parameter description:

Version corresponding to the alias.

Constraints:

None

Value range:

None

Default value:

None

description

No

String

Parameter description:

Description of the alias.

Constraints:

None

Value range:

A maximum of 512 characters

Default value:

None

additional_version_weights

No

Map<String,Integer>

Parameter description:

Traffic shifting by percentage.

Constraints:

None

Value range:

[0, 100]

Default value:

None

additional_version_strategy

No

Map<String,VersionStrategy>

Parameter description:

Gray release policy information.

Constraints:

None

Value range:

None

Default value:

None

Table 4 VersionStrategy

Parameter

Mandatory

Type

Description

rules

No

Array of VersionStrategyRules objects

Parameter description:

Rules.

combine_type

No

String

Parameter description:

Rule aggregation mode.

Constraints:

N/A

Value range:

and: All rules must be met.

or: Only one rule needs to be met.

Default value:

N/A

Table 5 VersionStrategyRules

Parameter

Mandatory

Type

Description

rule_type

No

String

Parameter description:

Gray release policy rule type.

Constraints:

None

Value range:

Header

Default value:

None

param

No

String

Parameter description:

Parameter name of the gray release policy rule.

Constraints:

Only letters, digits, underscores (_), and hyphens (-) are allowed.

Value range:

None

Default value:

None

op

No

String

Parameter description:

Operator of the gray release policy rule.

Constraints:

None

Value range:

Equal

in: include

Default value:

None

value

No

String

Parameter description:

Value of the gray release policy rule.

Constraints:

Only letters, digits, underscores (_), and hyphens (-) are allowed.

Value range:

If op is in, the value is a multi-value string separated by commas (,).

If op is =, the value is a character string.

Default value:

None

Response Parameters

Status code: 200

Table 6 Response body parameters

Parameter

Type

Description

name

String

Parameter description:

Alias to be queried.

Value range:

None

version

String

Parameter description:

Version corresponding to the alias.

Value range:

None

description

String

Parameter description:

Description of the alias.

Value range:

None

last_modified

String

Parameter description:

Time when the alias was last modified.

Value range:

None

alias_urn

String

Parameter description:

URN of the alias.

Value range:

None

additional_version_weights

Map<String,Integer>

Parameter description:

Traffic shifting by percentage.

Value range:

None

additional_version_strategy

Map<String,VersionStrategy>

Traffic shifting by rule.

Table 7 VersionStrategy

Parameter

Type

Description

rules

Array of VersionStrategyRules objects

Parameter description:

Rules.

combine_type

String

Parameter description:

Rule aggregation mode.

Table 8 VersionStrategyRules

Parameter

Type

Description

rule_type

String

Parameter description:

Gray release policy rule type.

param

String

Parameter description:

Parameter name of the gray release policy rule.

op

String

Parameter description:

Operator of the gray release policy rule.

value

String

Parameter description:

Value of the gray release policy rule.

Status code: 400

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 401

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 403

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 404

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Status code: 500

Table 13 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

error_msg

String

Error message.

Example Requests

  • Create an alias named a1 for version v1 of a function.

    POST https://{Endpoint}/v2/{project_id}/fgs/functions/{function_urn}/aliases
    
    {
      "name" : "a1",
      "version" : "v1"
    }
  • Create an alias named a1 for version v1 of a function, enable Traffic Shifting, and set Weight of version v2 to 50%.

    POST https://{Endpoint}/v2/{project_id}/fgs/functions/{function_urn}/aliases
    
    {
      "name" : "a1",
      "version" : "v1",
      "additional_version_weights" : {
        "v2" : 50
      }
    }
  • Create an alias named a1 for version v1 of a function, enable Traffic Shifting, and set version v2 to shift traffic by Rule.

    POST https://{Endpoint}/v2/{project_id}/fgs/functions/{function_urn}/aliases
    
    {
      "name" : "a1",
      "version" : "v1",
      "additional_version_strategy" : {
        "v2" : {
          "combine_type" : "and",
          "rules" : [ {
            "rule_type" : "Header",
            "param" : "version",
            "op" : "=",
            "value" : "v1"
          } ]
        }
      }
    }

Example Responses

Status code: 200

{
  "name" : "a1",
  "version" : "latest",
  "description" : "",
  "last_modified" : "2019-10-31 11:37:58",
  "alias_urn" : "urn:fss:{region}:46b6f338fc3445b8846c71dfb1fbxxxx:function:default:xxxxx:!a1"
}

Status code: 404

{
  "error_code" : "FSS.1051",
  "error_msg" : "Not found the function"
}

SDK Sample Code

The SDK sample code is as follows.

Java

  • Create an alias named a1 for version v1 of a function.

     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 CreateVersionAliasSolution {
    
        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();
            CreateVersionAliasRequest request = new CreateVersionAliasRequest();
            request.withFunctionUrn("{function_urn}");
            CreateVersionAliasRequestBody body = new CreateVersionAliasRequestBody();
            body.withVersion("v1");
            body.withName("a1");
            request.withBody(body);
            try {
                CreateVersionAliasResponse response = client.createVersionAlias(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());
            }
        }
    }
    
  • Create an alias named a1 for version v1 of a function, enable Traffic Shifting, and set Weight of version v2 to 50%.

     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
    57
    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.*;
    
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateVersionAliasSolution {
    
        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();
            CreateVersionAliasRequest request = new CreateVersionAliasRequest();
            request.withFunctionUrn("{function_urn}");
            CreateVersionAliasRequestBody body = new CreateVersionAliasRequestBody();
            Map<String, Integer> listbodyAdditionalVersionWeights = new HashMap<>();
            listbodyAdditionalVersionWeights.put("v2", 50);
            body.withAdditionalVersionWeights(listbodyAdditionalVersionWeights);
            body.withVersion("v1");
            body.withName("a1");
            request.withBody(body);
            try {
                CreateVersionAliasResponse response = client.createVersionAlias(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());
            }
        }
    }
    
  • Create an alias named a1 for version v1 of a function, enable Traffic Shifting, and set version v2 to shift traffic by Rule.

     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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    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.*;
    
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.util.HashMap;
    
    public class CreateVersionAliasSolution {
    
        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();
            CreateVersionAliasRequest request = new CreateVersionAliasRequest();
            request.withFunctionUrn("{function_urn}");
            CreateVersionAliasRequestBody body = new CreateVersionAliasRequestBody();
            List<VersionStrategyRules> listAdditionalVersionStrategyRules = new ArrayList<>();
            listAdditionalVersionStrategyRules.add(
                new VersionStrategyRules()
                    .withRuleType(VersionStrategyRules.RuleTypeEnum.fromValue("Header"))
                    .withParam("version")
                    .withOp(VersionStrategyRules.OpEnum.fromValue("="))
                    .withValue("v1")
            );
            VersionStrategy additionalVersionStrategyAdditionalVersionStrategy = new VersionStrategy();
            additionalVersionStrategyAdditionalVersionStrategy.withRules(listAdditionalVersionStrategyRules)
                .withCombineType(VersionStrategy.CombineTypeEnum.fromValue("and"));
            Map<String, VersionStrategy> listbodyAdditionalVersionStrategy = new HashMap<>();
            listbodyAdditionalVersionStrategy.put("v2", additionalVersionStrategyAdditionalVersionStrategy);
            body.withAdditionalVersionStrategy(listbodyAdditionalVersionStrategy);
            body.withVersion("v1");
            body.withName("a1");
            request.withBody(body);
            try {
                CreateVersionAliasResponse response = client.createVersionAlias(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

  • Create an alias named a1 for version v1 of a function.

     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 = CreateVersionAliasRequest()
            request.function_urn = "{function_urn}"
            request.body = CreateVersionAliasRequestBody(
                version="v1",
                name="a1"
            )
            response = client.create_version_alias(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Create an alias named a1 for version v1 of a function, enable Traffic Shifting, and set Weight of version v2 to 50%.

     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
    # 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 = CreateVersionAliasRequest()
            request.function_urn = "{function_urn}"
            listAdditionalVersionWeightsbody = {
                "v2": 50
            }
            request.body = CreateVersionAliasRequestBody(
                additional_version_weights=listAdditionalVersionWeightsbody,
                version="v1",
                name="a1"
            )
            response = client.create_version_alias(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Create an alias named a1 for version v1 of a function, enable Traffic Shifting, and set version v2 to shift traffic by Rule.

     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
    # 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 = CreateVersionAliasRequest()
            request.function_urn = "{function_urn}"
            listRulesAdditionalVersionStrategy = [
                VersionStrategyRules(
                    rule_type="Header",
                    param="version",
                    op="=",
                    value="v1"
                )
            ]
            additionalVersionStrategyAdditionalVersionStrategy = VersionStrategy(
                rules=listRulesAdditionalVersionStrategy,
                combine_type="and"
            )
            listAdditionalVersionStrategybody = {
                "v2": additionalVersionStrategyAdditionalVersionStrategy
            }
            request.body = CreateVersionAliasRequestBody(
                additional_version_strategy=listAdditionalVersionStrategybody,
                version="v1",
                name="a1"
            )
            response = client.create_version_alias(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

  • Create an alias named a1 for version v1 of a function.

     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
    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.CreateVersionAliasRequest{}
    	request.FunctionUrn = "{function_urn}"
    	request.Body = &model.CreateVersionAliasRequestBody{
    		Version: "v1",
    		Name: "a1",
    	}
    	response, err := client.CreateVersionAlias(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Create an alias named a1 for version v1 of a function, enable Traffic Shifting, and set Weight of version v2 to 50%.

     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
    57
    58
    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.CreateVersionAliasRequest{}
    	request.FunctionUrn = "{function_urn}"
    	var listAdditionalVersionWeightsbody = map[string]int32{
            "v2": int32(50),
        }
    	request.Body = &model.CreateVersionAliasRequestBody{
    		AdditionalVersionWeights: listAdditionalVersionWeightsbody,
    		Version: "v1",
    		Name: "a1",
    	}
    	response, err := client.CreateVersionAlias(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Create an alias named a1 for version v1 of a function, enable Traffic Shifting, and set version v2 to shift traffic by Rule.

     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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    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.CreateVersionAliasRequest{}
    	request.FunctionUrn = "{function_urn}"
    	ruleTypeRules:= model.GetVersionStrategyRulesRuleTypeEnum().HEADER
    	paramRules:= "version"
    	opRules:= model.GetVersionStrategyRulesOpEnum().=
    	valueRules:= "v1"
    	var listRulesAdditionalVersionStrategy = []model.VersionStrategyRules{
            {
                RuleType: &ruleTypeRules,
                Param: &paramRules,
                Op: &opRules,
                Value: &valueRules,
            },
        }
    	combineTypeAdditionalVersionStrategy:= model.GetVersionStrategyCombineTypeEnum().AND
    	additionalVersionStrategyAdditionalVersionStrategy := model.VersionStrategy{
    		Rules: &listRulesAdditionalVersionStrategy,
    		CombineType: &combineTypeAdditionalVersionStrategy,
    	}
    	var listAdditionalVersionStrategybody = map[string](model.VersionStrategy){
            "v2": additionalVersionStrategyAdditionalVersionStrategy,
        }
    	request.Body = &model.CreateVersionAliasRequestBody{
    		AdditionalVersionStrategy: listAdditionalVersionStrategybody,
    		Version: "v1",
    		Name: "a1",
    	}
    	response, err := client.CreateVersionAlias(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.