Skip to content

Embedded stream and stream/promises don't work. #1158

@nabetti1720

Description

@nabetti1720

In the Node.js runtimes supported by AWS, awslambda.streamifyResponse() is available for response streaming functionality.

However, since it is not provided as an external package and it is difficult to verify in a local environment, experts have released lambda-stream.
https://www.npmjs.com/package/lambda-stream

This package uses node.js streams instead of Web Standard API streams, so I wondered if it might be possible to use it with the current LLRT, which exposes streams and stream/promises as polyfills, so I did a little testing.

index.js: A slightly modified version of the website example.

// index.js
import { pipeline } from 'node:stream/promises';
import { Readable } from 'node:stream';

import * as awslambda from 'lambda-stream';

export const echo = awslambda.streamifyResponse(async (event, responseStream, _context) => {
  // As an example, convert event to a readable stream.
  const requestStream = Readable.from(Buffer.from(JSON.stringify(event)));

  await pipeline(requestStream, responseStream);
});
START RequestId: 41597e4c-8fca-492a-bce2-34782c30ac8e Version: $LATEST
2025-09-16T10:50:31.699Z	41597e4c-8fca-492a-bce2-34782c30ac8e	ERROR	{
  errorType: 'TypeError',
  errorMessage: 'TypeError: Error converting from js 'object' into type 'EventEmitter'',
  stackTrace: '    at call (native)
    at <anonymous> (stream:2:43115)
    at destroyer (stream/promises:2:67249)
    at pipelineImpl (stream/promises:2:69238)
    at <anonymous> (stream/promises:2:80925)
    at Promise (native)
    at pipeline (stream/promises:2:80806)
    at <anonymous> (/var/task/index.js:9:18)
    at apply (__cjs:/var/task/node_modules/lambda-stream/dist/index.js:23:23)
',
  requestId: '41597e4c-8fca-492a-bce2-34782c30ac8e'
}
END RequestId: 41597e4c-8fca-492a-bce2-34782c30ac8e
REPORT RequestId: 41597e4c-8fca-492a-bce2-34782c30ac8e	Duration: 2.43 ms	Billed Duration: 82 ms	Memory Size: 128 MB	Max Memory Used: 29 MB	Init Duration: 79.16 ms	

If this works, we think it will expand the use cases if you attach it to globalThis.awslambda when building lambda flavors.
lambda-stream is not strictly a ResponseStreaming, so we need to implement the correct functionality.

For your information, @middy/core and hono/aws-lambda seems to assume awslambda.streamifyResponse().

EDIT: Sorry, this has already been reported in #318. You can close it, but I think something needs to be done about the issue where embedded stream and stream/promises don't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions