Modifying the Alias of a Function Version
Function
This API is used to modify the alias of 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
PUT /v2/{project_id}/fgs/functions/{function_urn}/aliases/{alias_name}
| 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 |
| alias_name | Yes | String | Parameter description: Alias to be modified. Constraints: The value can contain a maximum of 63 characters, including letters, digits, underscores (_), and hyphens (-). It must start with a letter and end with a letter or digit. Value range: Max. 63 characters. 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 |
|---|---|---|---|
| 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: Rule-based dark launch policy information. Constraints: None Value range: None Default value: None |
| 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 |
| 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
| 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: Unique ID of the alias version. Value range: None |
| additional_version_weights | Map<String,Integer> | Parameter description: Traffic shifting by percentage. Value 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
-
Update the function version of alias {alias_name} to latest, and configure v1 as the additional version with a traffic ratio of 9:1.
PUT https://{Endpoint}/v2/{project_id}/fgs/functions/{function_urn}/aliases/{alias_name} { "version" : "latest", "description" : "", "additional_version_weights" : { "v1" : 10 } } -
Update the function version of alias {alias_name} to v1, enable Traffic Shifting and set version v2 to shift traffic by Rule.
PUT https://{Endpoint}/v2/{project_id}/fgs/functions/{function_urn}/aliases/{alias_name} { "version" : "v1", "description" : "", "additional_version_strategy" : { "v2" : { "combine_type" : "and", "rules" : [ { "rule_type" : "Header", "param" : "version", "op" : "=", "value" : "v1" } ] } } }
Example Responses
Status code: 200
{
"name" : "dev",
"version" : "latest",
"description" : "",
"last_modified" : "2019-10-31 11:37:58",
"alias_urn" : "urn:fss:xxxxxxxx: 7aad83af3e8d42e99ac194e8419e2c9b:function:default:test:!dev",
"additional_version_weights" : {
"v1" : 10
}
} Status code: 404
{
"error_code" : "FSS.1051",
"error_msg" : "Not found the function"
} SDK Sample Code
The SDK sample code is as follows.
Java
-
Update the function version of alias {alias_name} to latest, and configure v1 as the additional version with a traffic ratio of 9:1.
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 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 UpdateVersionAliasSolution { 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(); UpdateVersionAliasRequest request = new UpdateVersionAliasRequest(); request.withAliasName("{alias_name}"); request.withFunctionUrn("{function_urn}"); UpdateVersionAliasRequestBody body = new UpdateVersionAliasRequestBody(); Map<String, Integer> listbodyAdditionalVersionWeights = new HashMap<>(); listbodyAdditionalVersionWeights.put("v1", 10); body.withAdditionalVersionWeights(listbodyAdditionalVersionWeights); body.withDescription(""); body.withVersion("latest"); request.withBody(body); try { UpdateVersionAliasResponse response = client.updateVersionAlias(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()); } } }
-
Update the function version of alias {alias_name} to v1, 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
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 UpdateVersionAliasSolution { 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(); UpdateVersionAliasRequest request = new UpdateVersionAliasRequest(); request.withAliasName("{alias_name}"); request.withFunctionUrn("{function_urn}"); UpdateVersionAliasRequestBody body = new UpdateVersionAliasRequestBody(); 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.withDescription(""); body.withVersion("v1"); request.withBody(body); try { UpdateVersionAliasResponse response = client.updateVersionAlias(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
-
Update the function version of alias {alias_name} to latest, and configure v1 as the additional version with a traffic ratio of 9:1.
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
# 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 = UpdateVersionAliasRequest() request.alias_name = "{alias_name}" request.function_urn = "{function_urn}" listAdditionalVersionWeightsbody = { "v1": 10 } request.body = UpdateVersionAliasRequestBody( additional_version_weights=listAdditionalVersionWeightsbody, description="", version="latest" ) response = client.update_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)
-
Update the function version of alias {alias_name} to v1, 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
# 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 = UpdateVersionAliasRequest() request.alias_name = "{alias_name}" 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 = UpdateVersionAliasRequestBody( additional_version_strategy=listAdditionalVersionStrategybody, description="", version="v1" ) response = client.update_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
-
Update the function version of alias {alias_name} to latest, and configure v1 as the additional version with a traffic ratio of 9:1.
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
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.UpdateVersionAliasRequest{} request.AliasName = "{alias_name}" request.FunctionUrn = "{function_urn}" var listAdditionalVersionWeightsbody = map[string]int32{ "v1": int32(10), } descriptionUpdateVersionAliasRequestBody:= "" request.Body = &model.UpdateVersionAliasRequestBody{ AdditionalVersionWeights: listAdditionalVersionWeightsbody, Description: &descriptionUpdateVersionAliasRequestBody, Version: "latest", } response, err := client.UpdateVersionAlias(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Update the function version of alias {alias_name} to v1, 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 76 77
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.UpdateVersionAliasRequest{} request.AliasName = "{alias_name}" request.FunctionUrn = "{function_urn}" ruleTypeRules:= model.GetVersionStrategyRulesRuleTypeEnum().HEADER paramRules:= "version" opRules:= model.GetVersionStrategyRulesOpEnum().= valueRules:= "v1" var listRulesAdditionalVersionStrategy = []model.VersionStrategyRules{ { RuleType: &ruleTypeRules, Param: ¶mRules, Op: &opRules, Value: &valueRules, }, } combineTypeAdditionalVersionStrategy:= model.GetVersionStrategyCombineTypeEnum().AND additionalVersionStrategyAdditionalVersionStrategy := model.VersionStrategy{ Rules: &listRulesAdditionalVersionStrategy, CombineType: &combineTypeAdditionalVersionStrategy, } var listAdditionalVersionStrategybody = map[string](model.VersionStrategy){ "v2": additionalVersionStrategyAdditionalVersionStrategy, } descriptionUpdateVersionAliasRequestBody:= "" request.Body = &model.UpdateVersionAliasRequestBody{ AdditionalVersionStrategy: listAdditionalVersionStrategybody, Description: &descriptionUpdateVersionAliasRequestBody, Version: "v1", } response, err := client.UpdateVersionAlias(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