diff --git a/docs/docs/services/stepfunctions.rst b/docs/docs/services/stepfunctions.rst index cdabcc009..c00c0d9e4 100644 --- a/docs/docs/services/stepfunctions.rst +++ b/docs/docs/services/stepfunctions.rst @@ -31,13 +31,40 @@ stepfunctions - [X] delete_state_machine - [ ] describe_activity - [X] describe_execution + + The status of every execution is set to 'RUNNING' by default. + Set the following environment variable if you want to get a FAILED status back: + + .. sourcecode:: bash + + SF_EXECUTION_HISTORY_TYPE=FAILURE + + - [ ] describe_map_run - [X] describe_state_machine - [ ] describe_state_machine_for_execution - [ ] get_activity_task - [X] get_execution_history + + A static list of successful events is returned by default. + Set the following environment variable if you want to get a static list of events for a failed execution: + + .. sourcecode:: bash + + SF_EXECUTION_HISTORY_TYPE=FAILURE + + - [ ] list_activities - [X] list_executions + + The status of every execution is set to 'RUNNING' by default. + Set the following environment variable if you want to get a FAILED status back: + + .. sourcecode:: bash + + SF_EXECUTION_HISTORY_TYPE=FAILURE + + - [ ] list_map_runs - [X] list_state_machines - [X] list_tags_for_resource diff --git a/moto/stepfunctions/models.py b/moto/stepfunctions/models.py index 318713d45..64d4eea45 100644 --- a/moto/stepfunctions/models.py +++ b/moto/stepfunctions/models.py @@ -230,7 +230,11 @@ class Execution: self.start_date = iso_8601_datetime_with_milliseconds(datetime.now()) self.state_machine_arn = state_machine_arn self.execution_input = execution_input - self.status = "RUNNING" + self.status = ( + "RUNNING" + if settings.get_sf_execution_history_type() == "SUCCESS" + else "FAILED" + ) self.stop_date = None def get_execution_history(self, roleArn): @@ -510,6 +514,14 @@ class StepFunctionBackend(BaseBackend): @paginate(pagination_model=PAGINATION_MODEL) def list_executions(self, state_machine_arn, status_filter=None): + """ + The status of every execution is set to 'RUNNING' by default. + Set the following environment variable if you want to get a FAILED status back: + + .. sourcecode:: bash + + SF_EXECUTION_HISTORY_TYPE=FAILURE + """ executions = self.describe_state_machine(state_machine_arn).executions if status_filter: @@ -519,6 +531,14 @@ class StepFunctionBackend(BaseBackend): return executions def describe_execution(self, execution_arn): + """ + The status of every execution is set to 'RUNNING' by default. + Set the following environment variable if you want to get a FAILED status back: + + .. sourcecode:: bash + + SF_EXECUTION_HISTORY_TYPE=FAILURE + """ self._validate_execution_arn(execution_arn) state_machine = self._get_state_machine_for_execution(execution_arn) exctn = next( @@ -532,6 +552,14 @@ class StepFunctionBackend(BaseBackend): return exctn def get_execution_history(self, execution_arn): + """ + A static list of successful events is returned by default. + Set the following environment variable if you want to get a static list of events for a failed execution: + + .. sourcecode:: bash + + SF_EXECUTION_HISTORY_TYPE=FAILURE + """ self._validate_execution_arn(execution_arn) state_machine = self._get_state_machine_for_execution(execution_arn) execution = next( diff --git a/tests/test_stepfunctions/test_stepfunctions.py b/tests/test_stepfunctions/test_stepfunctions.py index 31eb7f186..d68e17c2f 100644 --- a/tests/test_stepfunctions/test_stepfunctions.py +++ b/tests/test_stepfunctions/test_stepfunctions.py @@ -950,6 +950,12 @@ def test_state_machine_get_execution_history_contains_expected_failure_events_wh execution_history["events"].should.have.length_of(3) execution_history["events"].should.equal(expected_events) + exc = client.describe_execution(executionArn=execution["executionArn"]) + assert exc["status"] == "FAILED" + + exc = client.list_executions(stateMachineArn=sm["stateMachineArn"])["executions"][0] + assert exc["status"] == "FAILED" + def _get_default_role(): return "arn:aws:iam::" + ACCOUNT_ID + ":role/unknown_sf_role"