-
Notifications
You must be signed in to change notification settings - Fork 48
/
doc_cloudwatchlogs_test.go
38 lines (31 loc) · 1.18 KB
/
doc_cloudwatchlogs_test.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
package sparta
import (
"context"
"github.com/aws/aws-lambda-go/lambdacontext"
)
func cloudWatchLogsProcessor(ctx context.Context,
props map[string]interface{}) error {
lambdaCtx, _ := lambdacontext.FromContext(ctx)
Logger().Info().
Str("RequestID", lambdaCtx.AwsRequestID).
Msg("CloudWatch log event")
Logger().Info().Msg("CloudWatch Log event received")
return nil
}
func ExampleCloudWatchLogsPermission() {
var lambdaFunctions []*LambdaAWSInfo
cloudWatchLogsLambda, _ := NewAWSLambda(LambdaName(cloudWatchLogsProcessor),
cloudWatchLogsProcessor,
IAMRoleDefinition{})
cloudWatchLogsPermission := CloudWatchLogsPermission{}
cloudWatchLogsPermission.Filters = make(map[string]CloudWatchLogsSubscriptionFilter, 1)
cloudWatchLogsPermission.Filters["MyFilter"] = CloudWatchLogsSubscriptionFilter{
LogGroupName: "/aws/lambda/*",
}
cloudWatchLogsLambda.Permissions = append(cloudWatchLogsLambda.Permissions, cloudWatchLogsPermission)
lambdaFunctions = append(lambdaFunctions, cloudWatchLogsLambda)
mainErr := Main("CloudWatchLogs", "Registers for CloudWatch Logs", lambdaFunctions, nil, nil)
if mainErr != nil {
panic("Failed to invoke sparta.Main: %s" + mainErr.Error())
}
}