-
Notifications
You must be signed in to change notification settings - Fork 1
/
lambda_update_alias.go
54 lines (48 loc) · 1.5 KB
/
lambda_update_alias.go
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 kanarya
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lambda"
)
// LambdaUpdateAliasResponse is used to represent the response returned from
// UpdateAlias. The main use case of this struct is to track traffic shifted
// from one version to another.
type LambdaUpdateAliasResponse struct {
AliasArn string
AliasName string
CurrentVersion string
NewVersion string
CurrentWeight float64
}
// UpdateAlias is used to shift traffic from one version to another. version
// argument is the version to shift some traffic, and traffic argument
// stands for the amount of traffic to be shifted. For example, 0.2 means 20%
// traffic shift to the specified version.
func UpdateAlias(
client *lambda.Lambda,
lambdaPackage LambdaPackage,
version string,
traffic float64,
) (LambdaUpdateAliasResponse, error) {
resp := LambdaUpdateAliasResponse{}
result, err := client.UpdateAlias(
&lambda.UpdateAliasInput{
FunctionName: aws.String(lambdaPackage.Function.Name),
Name: aws.String(lambdaPackage.Alias.Name),
RoutingConfig: &lambda.AliasRoutingConfiguration{
AdditionalVersionWeights: map[string]*float64{
version: aws.Float64(traffic),
},
},
},
)
if err != nil {
return resp, err
}
return LambdaUpdateAliasResponse{
AliasArn: *result.AliasArn,
AliasName: *result.Name,
CurrentVersion: *result.FunctionVersion,
CurrentWeight: *result.RoutingConfig.AdditionalVersionWeights[version],
NewVersion: version,
}, nil
}