@@ -45,8 +45,16 @@ func (l *LocalStackAdapter) SendStatus(status LocalStackStatus) error {
45
45
}
46
46
47
47
type InvokeRequest struct {
48
- InvokeId string `json:"invoke-id"`
49
- Payload string `json:"payload"`
48
+ InvokeId string `json:"invoke-id"`
49
+ InvokedFunctionArn string `json:"invoked-function-arn"`
50
+ Payload string `json:"payload"`
51
+ }
52
+
53
+ type ErrorResponse struct {
54
+ ErrorMessage string `json:"errorMessage"`
55
+ ErrorType string `json:"errorType"`
56
+ RequestId string `json:"requestId"`
57
+ StackTrace []string `json:"stackTrace"`
50
58
}
51
59
52
60
func NewCustomInteropServer (lsOpts * LsOpts , delegate rapidcore.InteropServer , logCollector * LogCollector ) (server * CustomInteropServer ) {
@@ -84,25 +92,35 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
84
92
85
93
invokeStart := time .Now ()
86
94
err = server .Invoke (invokeResp , & interop.Invoke {
87
- ID : invokeR .InvokeId ,
88
- TraceID : "TraceID" , // r.Header.Get("X-Amzn-Trace-Id"),
89
- LambdaSegmentID : "LambdaSegmentID" , // r.Header.Get("X-Amzn-Segment-Id"),
90
- Payload : strings .NewReader (invokeR .Payload ), // r.Body,
91
- CorrelationID : "invokeCorrelationID" ,
92
- NeedDebugLogs : true ,
95
+ ID : invokeR .InvokeId ,
96
+ TraceID : "TraceID" , // r.Header.Get("X-Amzn-Trace-Id"),
97
+ LambdaSegmentID : "LambdaSegmentID" , // r.Header.Get("X-Amzn-Segment-Id"),
98
+ Payload : strings .NewReader (invokeR .Payload ), // r.Body,
99
+ CorrelationID : "invokeCorrelationID" ,
100
+ NeedDebugLogs : true ,
101
+ InvokedFunctionArn : invokeR .InvokedFunctionArn ,
93
102
})
94
103
inv := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_TIMEOUT" )
95
104
timeoutDuration , _ := time .ParseDuration (inv + "s" )
96
105
memorySize := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE" )
97
106
PrintEndReports (invokeR .InvokeId , "" , memorySize , invokeStart , timeoutDuration , logCollector )
98
107
99
- serializedResponse , err := json .Marshal (logCollector .getLogs ())
100
- if err == nil {
101
- _ , err = http .Post (server .upstreamEndpoint + "/invocations/" + invokeR .InvokeId + "/logs" , "application/json" , bytes .NewReader (serializedResponse ))
108
+ serializedLogs , err2 := json .Marshal (logCollector .getLogs ())
109
+ if err2 == nil {
110
+ _ , err2 = http .Post (server .upstreamEndpoint + "/invocations/" + invokeR .InvokeId + "/logs" , "application/json" , bytes .NewReader (serializedLogs ))
111
+ // TODO: handle err
102
112
}
103
113
104
- if err != nil {
114
+ callErr := false
115
+ var errR ErrorResponse
116
+ err := json .Unmarshal (invokeResp .Body , & errR )
117
+ if err == nil {
118
+ callErr = true
119
+ } else {
105
120
log .Error (err )
121
+ }
122
+
123
+ if callErr {
106
124
_ , err = http .Post (server .upstreamEndpoint + "/invocations/" + invokeR .InvokeId + "/error" , "application/json" , bytes .NewReader (invokeResp .Body ))
107
125
if err != nil {
108
126
log .Error (err )
0 commit comments