-
Notifications
You must be signed in to change notification settings - Fork 48
/
doc_sespermission_test.go
94 lines (83 loc) · 2.86 KB
/
doc_sespermission_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package sparta
import (
"context"
"github.com/aws/aws-lambda-go/lambdacontext"
)
func sesLambdaProcessor(ctx context.Context,
props map[string]interface{}) (map[string]interface{}, error) {
lambdaCtx, _ := lambdacontext.FromContext(ctx)
Logger().Info().
Str("RequestID", lambdaCtx.AwsRequestID).
Interface("Properties", props).
Msg("Lambda event")
return props, nil
}
func ExampleSESPermission_messageBody() {
var lambdaFunctions []*LambdaAWSInfo
// Define the IAM role
roleDefinition := IAMRoleDefinition{}
sesLambda, _ := NewAWSLambda(LambdaName(sesLambdaProcessor),
sesLambdaProcessor,
roleDefinition)
// Add a Permission s.t. the Lambda function is automatically invoked
// in response to inbound email
lambdaSESPermission := SESPermission{
BasePermission: BasePermission{
SourceArn: "*",
},
InvocationType: "Event",
}
// Store the message body in a newly provisioned S3 bucket
bodyStorage, _ := lambdaSESPermission.NewMessageBodyStorageResource("MessageBody")
lambdaSESPermission.MessageBodyStorage = bodyStorage
// Add some custom ReceiptRules.
lambdaSESPermission.ReceiptRules = append(lambdaSESPermission.ReceiptRules,
ReceiptRule{
Name: "Default",
Recipients: []string{},
TLSPolicy: "Optional",
})
sesLambda.Permissions = append(sesLambda.Permissions, lambdaSESPermission)
lambdaFunctions = append(lambdaFunctions, sesLambda)
mainErr := Main("SESLambdaApp", "Registers for SES events and saves the MessageBody", lambdaFunctions, nil, nil)
if mainErr != nil {
panic("Failed to invoke sparta.Main: %s" + mainErr.Error())
}
}
func ExampleSESPermission_headersOnly() {
var lambdaFunctions []*LambdaAWSInfo
// Define the IAM role
roleDefinition := IAMRoleDefinition{}
sesLambda, _ := NewAWSLambda(LambdaName(sesLambdaProcessor),
sesLambdaProcessor,
roleDefinition)
// Add a Permission s.t. the Lambda function is automatically invoked
// in response to inbound email
lambdaSESPermission := SESPermission{
BasePermission: BasePermission{
SourceArn: "*",
},
InvocationType: "Event",
}
// Add some custom ReceiptRules. Rules will be inserted (evaluated) in their
// array rank order.
lambdaSESPermission.ReceiptRules = make([]ReceiptRule, 0)
lambdaSESPermission.ReceiptRules = append(lambdaSESPermission.ReceiptRules,
ReceiptRule{
Name: "Special",
Recipients: []string{"somebody@mydomain.io"},
TLSPolicy: "Optional",
})
lambdaSESPermission.ReceiptRules = append(lambdaSESPermission.ReceiptRules,
ReceiptRule{
Name: "Default",
Recipients: []string{},
TLSPolicy: "Optional",
})
sesLambda.Permissions = append(sesLambda.Permissions, lambdaSESPermission)
lambdaFunctions = append(lambdaFunctions, sesLambda)
mainErr := Main("SESLambdaApp", "Registers for SES events", lambdaFunctions, nil, nil)
if mainErr != nil {
panic("Failed to invoke sparta.Main: %s" + mainErr.Error())
}
}