@@ -45,8 +45,16 @@ func (l *LocalStackAdapter) SendStatus(status LocalStackStatus) error {
4545}
4646
4747type 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"`
5058}
5159
5260func NewCustomInteropServer (lsOpts * LsOpts , delegate rapidcore.InteropServer , logCollector * LogCollector ) (server * CustomInteropServer ) {
@@ -84,25 +92,35 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
8492
8593 invokeStart := time .Now ()
8694 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 ,
93102 })
94103 inv := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_TIMEOUT" )
95104 timeoutDuration , _ := time .ParseDuration (inv + "s" )
96105 memorySize := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE" )
97106 PrintEndReports (invokeR .InvokeId , "" , memorySize , invokeStart , timeoutDuration , logCollector )
98107
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
102112 }
103113
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 {
105120 log .Error (err )
121+ }
122+
123+ if callErr {
106124 _ , err = http .Post (server .upstreamEndpoint + "/invocations/" + invokeR .InvokeId + "/error" , "application/json" , bytes .NewReader (invokeResp .Body ))
107125 if err != nil {
108126 log .Error (err )
0 commit comments