forked from mweagle/Sparta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_test.go
74 lines (62 loc) · 2.17 KB
/
data_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
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
73
74
package sparta
import (
"context"
)
const LambdaExecuteARN = "LambdaExecutor"
const s3BucketSourceArn = "arn:aws:s3:::sampleBucket"
const snsTopicSourceArn = "arn:aws:sns:us-west-2:000000000000:someTopic"
const dynamoDBTableArn = "arn:aws:dynamodb:us-west-2:000000000000:table/sampleTable"
func mockLambda1(ctx context.Context) (string, error) {
return "mockLambda1!", nil
}
func mockLambda2(ctx context.Context) (string, error) {
return "mockLambda2!", nil
}
func mockLambda3(ctx context.Context) (string, error) {
return "mockLambda3!", nil
}
func testLambdaData() []*LambdaAWSInfo {
var lambdaFunctions []*LambdaAWSInfo
//////////////////////////////////////////////////////////////////////////////
// Lambda function 1
lambdaFn := HandleAWSLambda(LambdaName(mockLambda1),
mockLambda1,
LambdaExecuteARN)
lambdaFn.Permissions = append(lambdaFn.Permissions, S3Permission{
BasePermission: BasePermission{
SourceArn: s3BucketSourceArn,
},
// Event Filters are defined at
// http://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html
Events: []string{"s3:ObjectCreated:*", "s3:ObjectRemoved:*"},
})
lambdaFn.Permissions = append(lambdaFn.Permissions, SNSPermission{
BasePermission: BasePermission{
SourceArn: snsTopicSourceArn,
},
})
lambdaFn.EventSourceMappings = append(lambdaFn.EventSourceMappings, &EventSourceMapping{
StartingPosition: "TRIM_HORIZON",
EventSourceArn: dynamoDBTableArn,
BatchSize: 10,
})
lambdaFunctions = append(lambdaFunctions, lambdaFn)
//////////////////////////////////////////////////////////////////////////////
// Lambda function 2
lambdaFunctions = append(lambdaFunctions, HandleAWSLambda(LambdaName(mockLambda2),
mockLambda2,
LambdaExecuteARN))
//////////////////////////////////////////////////////////////////////////////
// Lambda function 3
// https://github.com/mweagle/Sparta/pull/1
lambdaFn3 := HandleAWSLambda(LambdaName(mockLambda3),
mockLambda3,
LambdaExecuteARN)
lambdaFn3.Permissions = append(lambdaFn3.Permissions, SNSPermission{
BasePermission: BasePermission{
SourceArn: snsTopicSourceArn,
},
})
lambdaFunctions = append(lambdaFunctions, lambdaFn3)
return lambdaFunctions
}