aws-cdk-lib.aws_stepfunctions.FailProps

interface FailProps

LanguageType name
.NETAmazon.CDK.AWS.StepFunctions.FailProps
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsstepfunctions#FailProps
Javasoftware.amazon.awscdk.services.stepfunctions.FailProps
Pythonaws_cdk.aws_stepfunctions.FailProps
TypeScript (source)aws-cdk-lib » aws_stepfunctions » FailProps

Properties for defining a Fail state.

Example

import * as lambda from 'aws-cdk-lib/aws-lambda';

declare const submitLambda: lambda.Function;
declare const getStatusLambda: lambda.Function;

const submitJob = new tasks.LambdaInvoke(this, 'Submit Job', {
  lambdaFunction: submitLambda,
  // Lambda's result is in the attribute `guid`
  outputPath: '$.guid',
});

const waitX = new sfn.Wait(this, 'Wait X Seconds', {
  time: sfn.WaitTime.secondsPath('$.waitSeconds'),
});

const getStatus = new tasks.LambdaInvoke(this, 'Get Job Status', {
  lambdaFunction: getStatusLambda,
  // Pass just the field named "guid" into the Lambda, put the
  // Lambda's result in a field called "status" in the response
  inputPath: '$.guid',
  outputPath: '$.status',
});

const jobFailed = new sfn.Fail(this, 'Job Failed', {
  cause: 'AWS Batch Job Failed',
  error: 'DescribeJob returned FAILED',
});

const finalStatus = new tasks.LambdaInvoke(this, 'Get Final Job Status', {
  lambdaFunction: getStatusLambda,
  // Use "guid" field as input
  inputPath: '$.guid',
  outputPath: '$.Payload',
});

const definition = submitJob
  .next(waitX)
  .next(getStatus)
  .next(new sfn.Choice(this, 'Job Complete?')
    // Look at the "status" field
    .when(sfn.Condition.stringEquals('$.status', 'FAILED'), jobFailed)
    .when(sfn.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus)
    .otherwise(waitX));

new sfn.StateMachine(this, 'StateMachine', {
  definition,
  timeout: Duration.minutes(5),
});

Properties

NameTypeDescription
cause?stringA description for the cause of the failure.
comment?stringAn optional description for this state.
error?stringError code used to represent this failure.

cause?

Type: string (optional, default: No description)

A description for the cause of the failure.


comment?

Type: string (optional, default: No comment)

An optional description for this state.


error?

Type: string (optional, default: No error code)

Error code used to represent this failure.