-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlambda_update_function.go
45 lines (37 loc) · 1.16 KB
/
lambda_update_function.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
package kanarya
import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/lambda"
)
// LambdaUpdateFunctionResponse is used to reflect the response returned from
// UpdateFunctionCode function.
type LambdaUpdateFunctionResponse struct {
FunctionArn string
FunctionName string
LastUpdateStatus string
}
// UpdateFunctionCode updates the function code of a lambda located on $LATEST.
// In later stages, new versions can be created from the updated $LATEST.
func UpdateFunctionCode(
client *lambda.Lambda,
lambdaPackage LambdaPackage,
) (LambdaUpdateFunctionResponse, error) {
resp := LambdaUpdateFunctionResponse{}
result, err := client.UpdateFunctionCode(
&lambda.UpdateFunctionCodeInput{
FunctionName: aws.String(lambdaPackage.Function.Name),
S3Bucket: aws.String(lambdaPackage.Bucket.Name),
S3Key: aws.String(lambdaPackage.Bucket.Key),
},
)
if err != nil {
return resp, err
}
log.Println("Lambda function code updated...")
return LambdaUpdateFunctionResponse{
FunctionArn: *result.FunctionArn,
FunctionName: *result.FunctionName,
LastUpdateStatus: *result.LastUpdateStatus,
}, nil
}