MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / lambdaWrapWithClient

Function lambdaWrapWithClient

cfn/wrap.go:27–74  ·  view source on GitHub ↗
(lambdaFunction CustomResourceFunction, client httpClient)

Source from the content-addressed store, hash-verified

25type CustomResourceFunction func(context.Context, Event) (physicalResourceID string, data map[string]interface{}, err error)
26
27func lambdaWrapWithClient(lambdaFunction CustomResourceFunction, client httpClient) (fn CustomResourceLambdaFunction) {
28 fn = func(ctx context.Context, event Event) (reason string, err error) {
29 r := NewResponse(&event)
30
31 // A previous physical resource id exists unless this is a create request.
32 fallbackPhysicalResourceID := event.PhysicalResourceID
33 if event.RequestType == RequestCreate {
34 // If this is a create request, the fallback should be the request ID
35 fallbackPhysicalResourceID = event.RequestID
36 }
37
38 funcDidPanic := true
39 defer func() {
40 if funcDidPanic {
41 r.Status = StatusFailed
42 r.Reason = "Function panicked, see log stream for details"
43 r.PhysicalResourceID = fallbackPhysicalResourceID
44 // FIXME: something should be done if an error is returned here
45 _ = r.sendWith(client)
46 }
47 }()
48
49 r.PhysicalResourceID, r.Data, err = lambdaFunction(ctx, event)
50 funcDidPanic = false
51
52 if r.PhysicalResourceID == "" {
53 r.PhysicalResourceID = fallbackPhysicalResourceID
54 log.Printf("PhysicalResourceID not set. Using fallback PhysicalResourceID: %s\n", r.PhysicalResourceID)
55 }
56
57 if err != nil {
58 r.Status = StatusFailed
59 r.Reason = err.Error()
60 log.Printf("sending status failed: %s\n", r.Reason)
61 } else {
62 r.Status = StatusSuccess
63 }
64
65 err = r.sendWith(client)
66 if err != nil {
67 reason = err.Error()
68 }
69
70 return
71 }
72
73 return
74}
75
76// LambdaWrap returns a CustomResourceLambdaFunction which is something lambda.Start()
77// will understand. The purpose of doing this is so that Response Handling boiler

Callers 6

LambdaWrapFunction · 0.85
TestPanicSendsFailureFunction · 0.85
TestWrappedErrorFunction · 0.85
TestWrappedSendFailureFunction · 0.85

Calls 3

sendWithMethod · 0.95
NewResponseFunction · 0.85
ErrorMethod · 0.45

Tested by 5

TestPanicSendsFailureFunction · 0.68
TestWrappedErrorFunction · 0.68
TestWrappedSendFailureFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…