-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
58 lines (49 loc) · 1.24 KB
/
main.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
57
58
package main
import (
"context"
"os"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"go.uber.org/zap"
)
// Sample lambda function in go for future needs
type config struct {
AWSRegion string
AWSDnsSecret string
IsValid bool
}
var logger *zap.Logger
var c config
func main() {
// Create logger.
var err error
logger, err = zap.NewProduction()
if err != nil {
panic("failed to create logger: " + err.Error())
}
// Load config.
c.IsValid = true
c.AWSRegion = os.Getenv("JETS_REGION")
if c.AWSRegion == "" {
logger.Error("env JETS_REGION not set")
c.IsValid = false
}
c.AWSDnsSecret = os.Getenv("JETS_DSN_SECRET")
if c.AWSDnsSecret == "" {
logger.Error("env JETS_DSN_SECRET not set")
c.IsValid = false
}
if !c.IsValid {
logger.Fatal("Invalid configuration, exiting program")
}
// Start handler.
lambda.Start(handler)
}
func handler(ctx context.Context, s3Event events.S3Event) (err error) {
logger.Info("Starting...")
for i, record := range s3Event.Records {
s3 := record.S3
logger.Info("Processing File Key", zap.Int("index", i), zap.Int("count", len(s3Event.Records)), zap.String("bucketName", s3.Bucket.Name), zap.String("objectKey", s3.Object.Key))
}
return
}