@@ -24,13 +24,13 @@ func (c *runtimeAPIClient) getNextInvocation() (string, []byte, error) {
2424 return "" , nil , err
2525 }
2626 defer conn .Close ()
27-
27+
2828 fmt .Fprintf (conn , "GET /2018-06-01/runtime/invocation/next HTTP/1.1\r \n Host: %s\r \n \r \n " , c .host )
29-
29+
3030 reader := bufio .NewReader (conn )
3131 var requestID string
3232 var contentLength int
33-
33+
3434 for {
3535 line , _ := reader .ReadString ('\n' )
3636 if strings .HasPrefix (line , "Lambda-Runtime-Aws-Request-Id:" ) {
@@ -43,7 +43,7 @@ func (c *runtimeAPIClient) getNextInvocation() (string, []byte, error) {
4343 break
4444 }
4545 }
46-
46+
4747 body := make ([]byte , contentLength )
4848 reader .Read (body )
4949 return requestID , body , nil
@@ -55,7 +55,7 @@ func (c *runtimeAPIClient) sendResponse(requestID string, response []byte) error
5555 return err
5656 }
5757 defer conn .Close ()
58-
58+
5959 fmt .Fprintf (conn , "POST /2018-06-01/runtime/invocation/%s/response HTTP/1.1\r \n Host: %s\r \n Content-Length: %d\r \n \r \n %s" , requestID , c .host , len (response ), response )
6060 return nil
6161}
@@ -66,7 +66,7 @@ func (c *runtimeAPIClient) sendError(requestID, errorMsg string) error {
6666 return err
6767 }
6868 defer conn .Close ()
69-
69+
7070 errorPayload := `{"errorMessage": "` + errorMsg + `", "errorType": "Runtime.HandlerError"}`
7171 fmt .Fprintf (conn , "POST /2018-06-01/runtime/invocation/%s/error HTTP/1.1\r \n Host: %s\r \n Content-Length: %d\r \n \r \n %s" , requestID , c .host , len (errorPayload ), errorPayload )
7272 return nil
@@ -75,6 +75,7 @@ func (c *runtimeAPIClient) sendError(requestID, errorMsg string) error {
7575func executeShellHandler (handlerFile , handlerFunc string , eventData []byte ) ([]byte , error ) {
7676 cmd := exec .Command ("bash" , "-c" , "source " + handlerFile + " && " + handlerFunc )
7777 cmd .Stdin = strings .NewReader (string (eventData ))
78+ cmd .Stderr = os .Stderr
7879 return cmd .Output ()
7980}
8081
0 commit comments