forked from newrelic/nri-flex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda.go
51 lines (40 loc) · 1.12 KB
/
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
/*
* Copyright 2019 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package integration
import (
"context"
"fmt"
"os"
"github.com/aws/aws-lambda-go/lambda"
"github.com/newrelic/nri-flex/internal/load"
logrus "github.com/sirupsen/logrus"
)
// LambdaCheck check if Flex is running within a Lambda and insights url and api key has been supplied
func LambdaCheck() bool {
if os.Getenv("LAMBDA_TASK_ROOT") == "" {
return false
}
load.LambdaName = os.Getenv("AWS_LAMBDA_FUNCTION_NAME")
load.Logrus.SetFormatter(&logrus.JSONFormatter{})
if load.Args.InsightsURL == "" || load.Args.InsightsAPIKey == "" {
load.Logrus.Fatal("lambda: missing insights URL and/or API key")
return false
}
return true
}
// Lambda handles lambda invocation
func Lambda() {
lambda.Start(HandleRequest)
}
// HandleRequest Handles incoming lambda request
func HandleRequest(ctx context.Context, event interface{}) (string, error) {
load.Logrus.Info("flex: running as lambda")
SetDefaults()
if event != nil {
load.IngestData = event
}
RunFlex("lambda")
return fmt.Sprintf("Flex Lambda Complete"), nil
}