FailProps

class aws_cdk.aws_stepfunctions.FailProps(*, cause=None, comment=None, error=None)

Bases: object

Properties for defining a Fail state.

Parameters
  • cause (Optional[str]) – A description for the cause of the failure. Default: No description

  • comment (Optional[str]) – An optional description for this state. Default: No comment

  • error (Optional[str]) – Error code used to represent this failure. Default: No error code

ExampleMetadata

infused

Example:

import aws_cdk.aws_lambda as lambda_

# submit_lambda: lambda.Function
# get_status_lambda: lambda.Function


submit_job = tasks.LambdaInvoke(self, "Submit Job",
    lambda_function=submit_lambda,
    # Lambda's result is in the attribute `Payload`
    output_path="$.Payload"
)

wait_x = sfn.Wait(self, "Wait X Seconds",
    time=sfn.WaitTime.seconds_path("$.waitSeconds")
)

get_status = tasks.LambdaInvoke(self, "Get Job Status",
    lambda_function=get_status_lambda,
    # Pass just the field named "guid" into the Lambda, put the
    # Lambda's result in a field called "status" in the response
    input_path="$.guid",
    output_path="$.Payload"
)

job_failed = sfn.Fail(self, "Job Failed",
    cause="AWS Batch Job Failed",
    error="DescribeJob returned FAILED"
)

final_status = tasks.LambdaInvoke(self, "Get Final Job Status",
    lambda_function=get_status_lambda,
    # Use "guid" field as input
    input_path="$.guid",
    output_path="$.Payload"
)

definition = submit_job.next(wait_x).next(get_status).next(sfn.Choice(self, "Job Complete?").when(sfn.Condition.string_equals("$.status", "FAILED"), job_failed).when(sfn.Condition.string_equals("$.status", "SUCCEEDED"), final_status).otherwise(wait_x))

sfn.StateMachine(self, "StateMachine",
    definition=definition,
    timeout=Duration.minutes(5)
)

Attributes

cause

A description for the cause of the failure.

Default

No description

Return type

Optional[str]

comment

An optional description for this state.

Default

No comment

Return type

Optional[str]

error

Error code used to represent this failure.

Default

No error code

Return type

Optional[str]