node.js – How to measure the data size of the events and total request that will be sent over to AWS kinesis?

In my nodejs APP, this is how I write events to a kinesis stream:

      const requestObj = {
        Records: poppedEvents.map((event) => ({
          Data: Buffer.from(event),
          PartitionKey: JSON.parse(event).metadata.event.sourceParentId
            ? JSON.parse(event).metadata.event.sourceParentId
            : JSON.parse(event).metadata.event.sourceId,
        })),
        StreamName: this.conf.stream_name,
      };
        const command = new PutRecordsCommand(requestObj);
        await client.send(command);

My question is, how do I know the size in bytes for each event and the total request?
I this is important info because AWS PutRecords has limit of 1mb per event and 5mb per request.

Read more here: Source link