generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 176
Labels
bugSomething isn't workingSomething isn't workingevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utilitygood-first-issueSomething that is suitable for those who want to start contributingSomething that is suitable for those who want to start contributingpending-releaseThis item has been merged and will be released soonThis item has been merged and will be released soon
Description
Expected Behavior
When a user creates a handler that returns a stream, we do a check to ensure that it is a readable stream using instanceOf
:
value instanceof Readable && |
However, a Duplex
stream is also readable but it fails the the type check above.
Current Behavior
If you create a streaming handler that returns a proxy response with a Duplex stream as the body, it get passed to JSON.stringify
rather than be read as a stream.
Code snippet
Example unit test:
import context from '@aws-lambda-powertools/testing-utils/context';
import {
Router,
} from '../../../../src/rest/index.js';
import { createTestEvent } from '../helpers.js';
const app = new Router();
app.get('/stream', async () => {
const stream = createDuplexStream();
return {
headers: {
'content-type': 'application/json',
},
statusCode: 200,
body: createDuplexStream
}
});
const result = app.resolve(createTestEvent('/stream', 'GET'), context);
// returns
// {"_events":{},"_readableState":{"highWaterMark":65536,"buffer":[],"bufferIndex":0,"length":0, "pipes":[],"awaitDrainWriters":null},
//"_writableState" {"highWaterMark":65536,"length":0,"corked":0,"writelen":0,"bufferedIndex":0,"pendingcb":0},"allowHalfOpen":true}
Steps to Reproduce
- Create an HTTP event handler to return a stream as in the code example above.
- Invoke the handler.
- Message returned is a JSONified version of the stream rather than reading it.
Possible Solution
Change the type guard instanceof
check to also check for Duplex
instances:
(value instanceof Readable || value instanceof Duplex)
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingevent-handlerThis item relates to the Event Handler UtilityThis item relates to the Event Handler Utilitygood-first-issueSomething that is suitable for those who want to start contributingSomething that is suitable for those who want to start contributingpending-releaseThis item has been merged and will be released soonThis item has been merged and will be released soon