I have a lambda responsible for running a simulation and returning the result to the requesting client. The result is 1 to 2 mbs in size. I read that streaming the data to the client using stream responses is the most performant way to relay that size of data, so that is what I have been attempting to setup.
My code looks like this:
const { Readable } = require('stream');
const pipeline = require("util").promisify(require('stream').pipeline);
exports.handler = awslambda.streamifyResponse(async (event, responseStream, _context) =>
{
// generate simulation result
matchResult = fs.readFileSync("/tmp/MatchResult.json");
const requestStream = Readable.from(Buffer.from(matchResult));
await pipeline(requestStream, responseStream);
responseStream.end();
}
The await pipeline(requestStream, responseStream);
does get run but I am not seeing any indication of a message being received or any errors on the lambda side indicating something is not setup correctly.
This is the yaml for the function:
RunSinulation:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
MemorySize: 4000
FunctionUrlConfig:
AuthType: AWS_IAM
InvokeMode: RESPONSE_STREAM
Policies:
- AmazonAPIGatewayInvokeFullAccess
- S3CrudPolicy:
BucketName: !Ref Bucket
Environment:
Variables:
WebsocketEndpoint:
Ref: WebsocketAPI
BucketName:
Ref: Bucket
Metadata:
Dockerfile: Dockerfile.dockerfile
DockerContext: ./images/RunSinulation/
I am using a C# WebsocketSharp as the client.
Am I missing something on the server side, or is there something special I need to do with the client to receive these messages? I appreciate any help that can be offered.