def test_fail_creation(): fail_state = Fail(state_id='Fail', error='ErrorA', cause='Kaiju attack', comment='This is a comment') assert fail_state.state_id == 'Fail' assert fail_state.error == 'ErrorA' assert fail_state.cause == 'Kaiju attack' assert fail_state.comment == 'This is a comment' assert fail_state.to_dict() == { 'Type': 'Fail', 'Comment': 'This is a comment', 'Error': 'ErrorA', 'Cause': 'Kaiju attack' }
def test_retry_fail_for_unsupported_state(): c1 = Choice('My Choice') with pytest.raises(ValueError): c1.add_catch( Catch(error_equals=["States.NoChoiceMatched"], next_step=Fail("ChoiceFailed")))
def test_append_states_after_terminal_state_will_fail(): with pytest.raises(ValueError): chain = Chain() chain.append(Pass('Pass')) chain.append(Fail('Fail')) chain.append(Pass('Pass2')) with pytest.raises(ValueError): chain = Chain() chain.append(Pass('Pass')) chain.append(Succeed('Succeed')) chain.append(Pass('Pass2'))
def test_catch_creation(): catch = Catch(error_equals=['States.ALL'], next_step=Fail('End')) assert catch.to_dict() == { 'ErrorEquals': ['States.ALL'], 'Next': 'End' }
def test_verify_fail_state_fields(): with pytest.raises(TypeError): Fail('Succeed', unknown_field='Unknown Field')
check_crawler_lambda = template.add_resource( serverless.Function( "checkCrawlerLambda", CodeUri="./check_crawler", Description="check-crawler-status", FunctionName='stepfunctions-glue-troposphere-check-lambda', Handler="handler.lambda_handler", Role=lambda_crawler_execution_role.get_att('Arn'), Runtime="python3.8", Timeout=30 )) ### Step Function #### fail_state = Fail("DataImportFailed") finish = sf.steps.Succeed(state_id='Finish') glue_import_to_s3_job = sf.steps.GlueStartJobRunStep( state_id='Import to s3 raw', wait_for_completion=True, timeout_seconds=7200, comment="Import database to s3", parameters={ "JobName": "${jobName}", "Arguments": { "--s3_external_bucket": "${s3ExternalBucket}", "--s3_internal_bucket": "${s3InternalBucket}", "--enable-glue-datacatalog": "true", "--enable-continuous-cloudwatch-log": "true", "--enable-s3-parquet-optimized-committer": "true",
# define execution input execution_input = ExecutionInput( schema={ 'AutoMLJobName': str, 'ModelName': str, 'S3InputData': str, 'IamRole': str, 'TargetColumnName': str, 'S3OutputData': str, 'Tags': dict, 'EndpointName': str, 'EndpointConfigName': str }) # TODO: make this a notification workflow_failure = Fail('WorkflowFailed') # create autopilot lambda step create_autopilot_job_step = LambdaStep( 'StartAutopilotJob', parameters={ 'FunctionName': 'CreateAutopilotJob', 'Payload': { 'Configuration': { 'AutoMLJobName': execution_input['AutoMLJobName'], 'S3InputData': execution_input['S3InputData'], 'IamRole': execution_input['IamRole'], 'TargetColumnName': execution_input['TargetColumnName'], 'S3OutputData': execution_input['S3OutputData'], 'Tags': execution_input['Tags'] }
def test_choice_example(): next_state = Task( 'NextState', resource='arn:aws:lambda:us-east-1:1234567890:function:NextState') choice_state = Choice('ChoiceState') choice_state.default_choice( Fail('DefaultState', error='DefaultStateError', cause='No Matches!')) choice_state.add_choice( ChoiceRule.NumericEquals(variable='$.foo', value=1), Chain([ Task('FirstMatchState', resource= 'arn:aws:lambda:us-east-1:1234567890:function:FirstMatchState' ), next_state ])) choice_state.add_choice( ChoiceRule.NumericEquals(variable='$.foo', value=2), Chain([ Task( 'SecondMatchState', resource= 'arn:aws:lambda:us-east-1:1234567890:function:SecondMatchState' ), next_state ])) chain = Chain() chain.append( Task( 'FirstState', resource='arn:aws:lambda:us-east-1:1234567890:function:StartLambda' )) chain.append(choice_state) result = Graph(chain).to_dict() assert result == { 'StartAt': 'FirstState', 'States': { 'FirstState': { 'Type': 'Task', 'Resource': 'arn:aws:lambda:us-east-1:1234567890:function:StartLambda', 'Next': 'ChoiceState' }, 'ChoiceState': { 'Type': 'Choice', 'Choices': [{ 'Variable': '$.foo', 'NumericEquals': 1, 'Next': 'FirstMatchState' }, { 'Variable': '$.foo', 'NumericEquals': 2, 'Next': 'SecondMatchState' }], 'Default': 'DefaultState' }, 'FirstMatchState': { 'Type': 'Task', 'Resource': 'arn:aws:lambda:us-east-1:1234567890:function:FirstMatchState', 'Next': 'NextState' }, 'SecondMatchState': { 'Type': 'Task', 'Resource': 'arn:aws:lambda:us-east-1:1234567890:function:SecondMatchState', 'Next': 'NextState' }, 'DefaultState': { 'Type': 'Fail', 'Error': 'DefaultStateError', 'Cause': 'No Matches!' }, 'NextState': { 'Type': 'Task', 'Resource': 'arn:aws:lambda:us-east-1:1234567890:function:NextState', 'End': True } } }