diff --git a/moto/stepfunctions/models.py b/moto/stepfunctions/models.py index 6217a6bc7..fedcb8e77 100644 --- a/moto/stepfunctions/models.py +++ b/moto/stepfunctions/models.py @@ -96,12 +96,12 @@ class StepFunctionBackend(BaseBackend): if sm: self.state_machines.remove(sm) - def start_execution(self, state_machine_arn): + def start_execution(self, state_machine_arn, name=None): state_machine_name = self.describe_state_machine(state_machine_arn).name execution = Execution(region_name=self.region_name, account_id=self._get_account_id(), state_machine_name=state_machine_name, - execution_name=str(uuid4()), + execution_name=name or str(uuid4()), state_machine_arn=state_machine_arn) self.executions.append(execution) return execution diff --git a/moto/stepfunctions/responses.py b/moto/stepfunctions/responses.py index 0a170aa57..902a860e5 100644 --- a/moto/stepfunctions/responses.py +++ b/moto/stepfunctions/responses.py @@ -86,7 +86,8 @@ class StepFunctionResponse(BaseResponse): @amzn_request_id def start_execution(self): arn = self._get_param('stateMachineArn') - execution = self.stepfunction_backend.start_execution(arn) + name = self._get_param('name') + execution = self.stepfunction_backend.start_execution(arn, name) response = {'executionArn': execution.execution_arn, 'startDate': execution.start_date} return 200, {}, json.dumps(response) diff --git a/tests/test_stepfunctions/test_stepfunctions.py b/tests/test_stepfunctions/test_stepfunctions.py index 6c7fd8e26..6c1e7e4c8 100644 --- a/tests/test_stepfunctions/test_stepfunctions.py +++ b/tests/test_stepfunctions/test_stepfunctions.py @@ -243,11 +243,26 @@ def test_state_machine_start_execution(): execution = client.start_execution(stateMachineArn=sm['stateMachineArn']) # execution['ResponseMetadata']['HTTPStatusCode'].should.equal(200) - expected_exec_name = 'arn:aws:states:' + region + ':' + _get_account_id() + ':execution:name:[a-zA-Z0-9-]+' + uuid_regex = '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}' + expected_exec_name = 'arn:aws:states:' + region + ':' + _get_account_id() + ':execution:name:' + uuid_regex execution['executionArn'].should.match(expected_exec_name) execution['startDate'].should.be.a(datetime) +@mock_stepfunctions +@mock_sts +def test_state_machine_start_execution_with_custom_name(): + client = boto3.client('stepfunctions', region_name=region) + # + sm = client.create_state_machine(name='name', definition=str(simple_definition), roleArn=_get_default_role()) + execution = client.start_execution(stateMachineArn=sm['stateMachineArn'], name='execution_name') + # + execution['ResponseMetadata']['HTTPStatusCode'].should.equal(200) + expected_exec_name = 'arn:aws:states:' + region + ':' + _get_account_id() + ':execution:name:execution_name' + execution['executionArn'].should.equal(expected_exec_name) + execution['startDate'].should.be.a(datetime) + + @mock_stepfunctions @mock_sts def test_state_machine_list_executions():