How to stream AWS Lambda response in node?

后端 未结 1 1184
谎友^
谎友^ 2021-01-17 15:26

I have an AWS Lambda function, and I need to invoke it from my node app and stream the result back to the client. I\'ve looked in the docs but can\'t see a way. I want to

相关标签:
1条回答
  • 2021-01-17 16:15

    The Javascript AWS SDK supports streaming the body of the API responses so API calls like getting a large S3 blob of binary data can be streamed to Javascript functions.

    lambda.invoke(lambdaDef)
    .createReadStream()
    .on('data', function(data) {
      console.log("Got data:", data.toString())
    })
    

    You'll get the Payload of the response as data.

    The Javascript lambda functions don't support any streaming options except for logging and inbound events, just a callback that returns a chunk of data.
    The Java SDK does have a specific handler for streams -com.amazonaws.services.lambda.runtime.RequestStreamHandler.

    0 讨论(0)
提交回复
热议问题