-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (37 loc) · 916 Bytes
/
Copy pathmain.go
File metadata and controls
42 lines (37 loc) · 916 Bytes
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
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"github.com/aws/aws-lambda-go/lambda"
)
// handler is the AWS Lambda entry point (invoked on a schedule by EventBridge).
func handler(ctx context.Context) (map[string]any, error) {
cfg, err := loadConfig(ctx)
if err != nil {
return nil, err
}
results, runErr := runAll(ctx, cfg)
return map[string]any{"results": results}, runErr
}
func main() {
// On Lambda this env var is always set: run the runtime loop.
if os.Getenv("AWS_LAMBDA_RUNTIME_API") != "" {
lambda.Start(handler)
return
}
// Local / CLI mode: run once, print JSON, exit non-zero on error.
ctx := context.Background()
cfg, err := loadConfig(ctx)
if err != nil {
log.Fatal(err)
}
results, runErr := runAll(ctx, cfg)
out, _ := json.MarshalIndent(map[string]any{"results": results}, "", " ")
fmt.Println(string(out))
if runErr != nil {
os.Exit(1)
}
}