xp-forge / lambda

AWS Lambda for the XP Framework
2 stars 0 forks source link

Support streaming #22

Closed thekid closed 1 year ago

thekid commented 1 year ago

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

thekid commented 1 year ago

Implemented in https://github.com/xp-forge/lambda/releases/tag/v5.0.0