-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmodel_lambda.go
56 lines (46 loc) · 1.21 KB
/
model_lambda.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
55
56
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/service/lambda"
)
type ModelLambda struct{}
func NewModelLambda() ModelLambda {
return ModelLambda{}
}
type ModelLambdaDeployOutput lambda.InvokeOutput
func (self ModelLambdaDeployOutput) Status() DeployStatus {
if *self.StatusCode != 200 {
return DeployStatusFail
}
return DeployStatusSuccess
}
func (self ModelLambdaDeployOutput) Message() string {
return string(self.Payload)
}
func (self ModelLambda) Deploy(pj DeployProject, phase string, option DeployOption) (o DeployOutput, err error) {
lambda, err := CreateLambdaInstance()
if err != nil {
return
}
tag := option.Tag
if tag == "" {
ecr, err := CreateECRInstance()
if err != nil {
return o, err
}
tag, err = ecr.FindImageTagByRegexp(pj.ECRRegistryId(), pj.ECRRepository(), pj.ImageTagRegexp(), pj.TargetRegexp(), ImageTagVars{Branch: option.Branch, Phase: phase})
if err != nil {
return o, err
}
}
ph := pj.FindPhase(phase)
payload, err := PayloadVars{Tag: tag}.Parse(ph.Payload)
if err != nil {
return
}
res, err := lambda.Invoke(pj.FuncName(), payload)
if res.FunctionError != nil {
return o, fmt.Errorf(string(res.Payload))
}
return ModelLambdaDeployOutput(*res), err
}