-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
72 lines (57 loc) · 1.16 KB
/
main.go
File metadata and controls
72 lines (57 loc) · 1.16 KB
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
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/aws/aws-lambda-go/lambda"
"github.com/nekrassov01/llcm"
)
var (
client *llcm.Client
filter string
desired string
)
func init() {
f := os.Getenv("FILTER")
if f == "" {
log.Fatal("environment variable FILTER not set")
}
filter = f
d := os.Getenv("DESIRED_STATE")
if d == "" {
log.Fatal("environment variable DESIRED_STATE not set")
}
desired = d
cfg, err := llcm.LoadConfig(context.Background(), "")
if err != nil {
log.Fatal(err)
}
client = llcm.NewClient(cfg)
log.Println("client created in init")
}
func handleRequest(ctx context.Context) error {
log.Println("handleRequest started")
w := os.Stdout
// initialize the manager
man := llcm.NewManager(client)
// set filter to the manager
if err := man.SetFilter(filter); err != nil {
return err
}
// set desired state to the manager
if err := man.SetDesiredState(desired); err != nil {
return err
}
// run apply operation
n, err := man.Apply(ctx, w)
if err != nil {
return err
}
fmt.Fprintf(w, "done: %d\n", n)
log.Println("handleRequest finished")
return nil
}
func main() {
lambda.Start(handleRequest)
}