Skip to content

Support streaming #22

@thekid

Description

@thekid

Announced in https://aws.amazon.com/de/blogs/compute/introducing-aws-lambda-response-streaming/, April 2023 - supported in Node runtimes.

JavaScript

Code in index.js:

exports.handler = awslambda.streamifyResponse(async (event, stream, context) => {
  stream.setContentType("text/plain");
  stream.write("[" + new Date().toISOString() + "] Hello world...\n");

  await new Promise(resolve => setTimeout(resolve, 1000));

  stream.write("[" + new Date().toISOString() + "] ...from Lambda\n");
  stream.end();
});

Code in serverless.yml:

service: node-streaming

provider:
  name: aws
  region: eu-central-1
  profile: default

functions:
  func:
    handler: index.handler
    runtime: nodejs18.x
    description: 'NodeJS Streaming'
    url:
      invokeMode: RESPONSE_STREAM

Invocation:
nodejs-lambda-stream

See also

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions