All files / lib/lambda deleteIndex.ts

100% Statements 13/13
66.66% Branches 2/3
100% Functions 1/1
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33        1x 3x     3x 3x 3x 3x   2x                 2x 8x     2x 2x   3x      
import { Handler } from "aws-lambda";
import * as os from "libs/opensearch-lib";
import { Index } from "../packages/shared-types/opensearch";
 
export const handler: Handler = async (event, __, callback) => {
  const response = {
    statusCode: 200,
  };
  let errorResponse = null;
  try {
    const { osDomain, indexNamespace = "" } = event;
    if (!osDomain) throw "osDomain cannot be undefined";
 
    const indices: Index[] = [
      `${indexNamespace}main`,
      `${indexNamespace}changelog`,
      `${indexNamespace}insights`,
      `${indexNamespace}types`,
      `${indexNamespace}subtypes`,
      `${indexNamespace}legacyinsights`,
      `${indexNamespace}cpocs`,
    ];
    for (const index of indices) {
      await os.deleteIndex(osDomain, index);
    }
  } catch (error: any) {
    response.statusCode = 500;
    errorResponse = error;
  } finally {
    callback(errorResponse, response);
  }
};