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 do something like this:
lambda.invoke(params).then(data => data.pipe(res))
or even
lambda.invoke(params, (err, data) => {
// data should be a pipeable stream instead of buffered
data.pipe(res)
})
Returning a valueIf you use the RequestResponse invocation type, such as Synchronous invocation, AWS Lambda returns the result of the Python function call to the client invoking the Lambda function (in the HTTP response to the invocation request, serialized into JSON).
AWS Lambda now supports Node. js 16 as both a managed runtime and a container base image. Developers creating serverless applications in Lambda with Node. js 16 can take advantage of new features such as support for Apple silicon for local development, the timers promises API, and enhanced performance.
Invocation metrics are binary indicators of the outcome of an invocation. For example, if the function returns an error, Lambda sends the Errors metric with a value of 1. To get a count of the number of function errors that occurred each minute, view the Sum of the Errors metric with a period of 1 minute.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With