-
Notifications
You must be signed in to change notification settings - Fork 48
/
doc_workflowhooks_test.go
66 lines (59 loc) · 1.6 KB
/
doc_workflowhooks_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
package sparta
import (
"archive/zip"
"context"
"io"
"strings"
"github.com/aws/aws-lambda-go/lambdacontext"
awsv2 "github.com/aws/aws-sdk-go-v2/aws"
"github.com/rs/zerolog"
)
const userdataResourceContents = `
{
"Hello" : "World",
}`
func helloZipLambda(ctx context.Context,
props map[string]interface{}) (string, error) {
lambdaCtx, _ := lambdacontext.FromContext(ctx)
Logger().Info().
Str("RequestID", lambdaCtx.AwsRequestID).
Interface("Properties", props).
Msg("Lambda event")
return "Event processed", nil
}
func archiveHook(ctx context.Context,
serviceName string,
zipWriter *zip.Writer,
awsConfig awsv2.Config,
noop bool,
logger *zerolog.Logger) (context.Context, error) {
logger.Info().Msg("Adding userResource")
resourceFileName := "userResource.json"
binaryWriter, binaryWriterErr := zipWriter.Create(resourceFileName)
if nil != binaryWriterErr {
return ctx, binaryWriterErr
}
userdataReader := strings.NewReader(userdataResourceContents)
_, copyErr := io.Copy(binaryWriter, userdataReader)
return ctx, copyErr
}
func ExampleWorkflowHooks() {
workflowHooks := WorkflowHooks{
Archives: []ArchiveHookHandler{ArchiveHookFunc(archiveHook)},
}
var lambdaFunctions []*LambdaAWSInfo
helloWorldLambda, _ := NewAWSLambda("PreexistingAWSLambdaRoleName",
helloZipLambda,
nil)
lambdaFunctions = append(lambdaFunctions, helloWorldLambda)
mainErr := MainEx("HelloWorldArchiveHook",
"Description for Hello World HelloWorldArchiveHook",
lambdaFunctions,
nil,
nil,
&workflowHooks,
false)
if mainErr != nil {
panic("Failed to invoke sparta.Main: %s" + mainErr.Error())
}
}