aws-sdk#StepFunctions TypeScript Examples

The following examples show how to use aws-sdk#StepFunctions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From cloudstructs with Apache License 2.0 6 votes vote down vote up
export async function startExecution(event: AWSLambda.CloudFormationCustomResourceEvent) {
  try {
    console.log('Event: %j', event);

    if (!process.env.STATE_MACHINE_ARN) {
      throw new Error('Missing STATE_MACHINE_ARN.');
    }

    // ignore DELETE event when the physical resource ID is the marker that
    // indicates that this DELETE is a subsequent DELETE to a failed CREATE
    // operation.
    if (event.RequestType === 'Delete' && event.PhysicalResourceId === CREATE_FAILED_PHYSICAL_ID_MARKER) {
      console.log('ignoring DELETE event caused by a failed CREATE event');
      await respond('SUCCESS', event);
      return;
    }

    const stepFunctions = new StepFunctions();
    await stepFunctions.startExecution({
      stateMachineArn: process.env.STATE_MACHINE_ARN,
      input: JSON.stringify(event),
    }).promise();
  } catch (err) {
    console.log(err);
    await respond('FAILED', {
      ...event,
      Reason: err.message,
    });
  }
}