Skip to content

Commit

Permalink
Merge pull request #58 from shogo82148/support-response-streaming
Browse files Browse the repository at this point in the history
support AWS Lambda response streaming
  • Loading branch information
shogo82148 authored Jun 19, 2023
2 parents 1507819 + 3bc187e commit 196c1ee
Show file tree
Hide file tree
Showing 6 changed files with 1,179 additions and 146 deletions.
6 changes: 5 additions & 1 deletion examples/function-urls/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ Resources:
Runtime: provided.al2
Timeout: 3
FunctionUrlConfig:
AuthType: NONE
AuthType: NONE
InvokeMode: RESPONSE_STREAM
Environment:
Variables:
RIDGENATIVE_INVOKE_MODE: RESPONSE_STREAM
21 changes: 21 additions & 0 deletions invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ridgenative
import (
"context"
"encoding/json"
"io"
"net/http"
)

Expand All @@ -29,3 +30,23 @@ func callBytesHandlerFunc(ctx context.Context, payload []byte, h handlerFunc) (r
}
return json.Marshal(resp)
}

func callHandlerFuncSteaming(ctx context.Context, payload []byte, h handlerFuncSteaming) (response io.ReadCloser, contentType string, err error) {
defer func() {
if v := recover(); v != nil {
err = lambdaPanicResponse(v)
}
}()

var req *request
if err := json.Unmarshal(payload, &req); err != nil {
return nil, "", err
}

r, w := io.Pipe()
contentType, err = h(ctx, req, w)
if err != nil {
return nil, "", err
}
return r, contentType, nil
}
Loading

0 comments on commit 196c1ee

Please sign in to comment.