async function putRecords()

in source/services/transformer/index.ts [198:243]


async function putRecords(records: Record[]) {
  logger.debug({
    label: "putRecords",
    message: "records put on firehose",
  });
  const params = {
    DeliveryStreamName: "" + process.env.DELIVERY_STREAM /* required */,
    Records: records,
  };
  const firehose = new Firehose({
    customUserAgent: process.env.CUSTOM_SDK_USER_AGENT,
  });
  await firehose.putRecordBatch(params).promise();

  // send usage metric to aws-solutions
  if (process.env.SEND_METRIC === "Yes") {
    logger.info({
      label: "putRecords",
      message: `sending metrics for indexed data`,
    });

    let totalItemSize = 0;
    records.forEach((r) => {
      totalItemSize += (r.Data as Buffer).byteLength;
    });
    logger.debug({
      label: "putRecords/sendMetric",
      message: `totalItemSize: ${totalItemSize}`,
    });

    const metric = {
      Solution: <string>process.env.SOLUTION_ID,
      UUID: <string>process.env.UUID,
      TimeStamp: new Date().toISOString().replace("T", " ").replace("Z", ""), // Date and time instant in a java.sql.Timestamp compatible format,
      Data: {
        TotalItemSize: "" + totalItemSize,
        Version: <string>process.env.SOLUTION_VERSION,
        Region: <string>process.env.AWS_REGION,
      },
    };
    await Metrics.sendAnonymousMetric(
      <string>process.env.METRICS_ENDPOINT,
      metric
    );
  }
}