All files / lib/lambda runReindex.ts

100% Statements 21/21
83.33% Branches 5/6
100% Functions 1/1
100% Lines 21/21

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 34 35 36 37 38 39 40 41 42 43 44 45 46        1x 4x 4x     4x 4x 4x 2x     2x   2x               2x 1x 1x     2x 1x 1x   1x     1x 1x 1x 1x   4x      
import { Handler } from "aws-lambda";
import { send, SUCCESS, FAILED } from "cfn-response-async";
import { SFNClient, StartExecutionCommand } from "@aws-sdk/client-sfn";
 
export const handler: Handler = async (event, context, callback) => {
  console.log("request:", JSON.stringify(event, undefined, 2));
  const response = {
    statusCode: 200,
  };
  let errorResponse = null;
  try {
    if (event.RequestType == "Create") {
      const stepFunctionsClient = new SFNClient({
        region: process.env.region,
      });
      const stateMachineArn = event.ResourceProperties.stateMachine;
 
      const startExecutionCommand = new StartExecutionCommand({
        stateMachineArn: stateMachineArn,
        input: JSON.stringify({
          cfnEvent: event,
          cfnContext: context,
        }),
      });
 
      const execution = await stepFunctionsClient.send(startExecutionCommand);
      console.log(`State machine execution started: ${execution.executionArn}`);
      console.log(
        "The state machine is now in charge of this resource, and will notify of success or failure upon completion.",
      );
    } else if (event.RequestType == "Update") {
      await send(event, context, SUCCESS, {}, "static");
    E} else if (event.RequestType == "Delete") {
      // need to delete all triggers here  to do
      await send(event, context, SUCCESS, {}, "static");
    }
  } catch (error) {
    console.log(error);
    response.statusCode = 500;
    errorResponse = error;
    await send(event, context, FAILED, {}, "static");
  } finally {
    callback(errorResponse, response);
  }
};