MCPcopy
hub / github.com/aws/aws-lambda-go / Example_ioReader

Function Example_ioReader

lambda/example_test.go:22–37  ·  view source on GitHub ↗

Handlers can return io.Reader to stream response data. This example uses a pipe to send data in chunks with delays. See https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html

()

Source from the content-addressed store, hash-verified

20//
21// See https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html
22func Example_ioReader() {
23 lambda.Start(func() (io.Reader, error) {
24 r, w := io.Pipe()
25 go func() {
26 defer w.Close()
27 _, _ = w.Write([]byte("<html><body>"))
28 time.Sleep(100 * time.Millisecond)
29 _, _ = w.Write([]byte("<h1>Hello</h1>"))
30 time.Sleep(100 * time.Millisecond)
31 _, _ = w.Write([]byte("<p>World!</p>"))
32 time.Sleep(100 * time.Millisecond)
33 _, _ = w.Write([]byte("</body></html>"))
34 }()
35 return r, nil
36 })
37}
38
39func ExampleWithContext() {
40 lambda.StartWithOptions(

Callers

nothing calls this directly

Calls 3

StartFunction · 0.92
WriteMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…