aws / aws/aws-lambda-go

How to use io.ReadCloser as Body of LambdaFunctionURLStreamingResponse

Open
#590 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
3.8k
Forks
578
Avg merge
8h 18m
Merged PRs (30d)
1

Description

Hi,

I want to use body from output of `s3.Client.GetObject` as body of `LambdaFunctionURLStreamingResponse`.
However, `out.Body` is `io.ReadCloser`, while `LambdaFunctionURLStreamingResponse.Body` is `io.Reader`.
I know that io.ReadCloser is compatible with io.Reader, but this would leave out.Body without being close.
How can I use body from output of s3 GetObject as body of LambdaFunctionURLStreamingResponse?

Below is the simplify version of my code
```go
func handler(
ctx context.Context,
req events.LambdaFunctionURLRequest,
) (res *events.LambdaFunctionURLStreamingResponse, err error) {

var s3Client *s3.Client
// ...
out, err := s3Client.GetObject(context.TODO(), &s3.GetObjectInput{
Bucket: &bucket,
Key: &key,
})
if err != nil {
return nil, err
}

resp := &events.LambdaFunctionURLStreamingResponse{
StatusCode: http.StatusOK,
Headers: map[string]string{"Content-Type": "application/x-ndjson"},
}

// What is the secure way to do this ?
resp.Body = out.Body

return resp, nil
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.