@@ -240,12 +240,14 @@ def get_existing_deployment(cls, name):
240240 workflow = StepFunctionsClient ().get (name )
241241 if workflow is not None :
242242 try :
243- start = json .loads (workflow ["definition" ])["States" ]["start" ]
243+ definition = json .loads (workflow ["definition" ])
244+ start_state_name = definition .get ("StartAt" , "start" )
245+ start = definition ["States" ][start_state_name ]
244246 parameters = start ["Parameters" ]["Parameters" ]
245247 return parameters .get ("metaflow.owner" ), parameters .get (
246248 "metaflow.production_token"
247249 )
248- except KeyError :
250+ except ( KeyError , TypeError , AttributeError ) :
249251 raise StepFunctionsException (
250252 "An existing non-metaflow "
251253 "workflow with the same name as "
@@ -271,17 +273,21 @@ def get_execution(cls, state_machine_name, name):
271273 )
272274 try :
273275 state_machine_arn = state_machine .get ("stateMachineArn" )
274- environment_vars = (
275- json .loads (state_machine .get ("definition" ))
276- .get ("States" )
277- .get ("start" )
278- .get ("Parameters" )
279- .get ("ContainerOverrides" )
280- .get ("Environment" )
281- )
282- parameters = {
283- item .get ("Name" ): item .get ("Value" ) for item in environment_vars
284- }
276+ definition = json .loads (state_machine .get ("definition" ))
277+ start_state_name = definition .get ("StartAt" , "start" )
278+ try :
279+ start = definition ["States" ][start_state_name ]
280+ environment_vars = start ["Parameters" ]["ContainerOverrides" ][
281+ "Environment"
282+ ]
283+ parameters = {
284+ item .get ("Name" ): item .get ("Value" ) for item in environment_vars
285+ }
286+ except (KeyError , TypeError , AttributeError ):
287+ raise StepFunctionsException (
288+ "A non-metaflow workflow *%s* already exists in AWS Step Functions."
289+ % state_machine_name
290+ )
285291 executions = client .list_executions (state_machine_arn , states = ["RUNNING" ])
286292 for execution in executions :
287293 if execution .get ("name" ) == name :
@@ -295,9 +301,11 @@ def get_execution(cls, state_machine_name, name):
295301 except KeyError :
296302 raise StepFunctionsException (
297303 "A non-metaflow workflow *%s* already exists in AWS Step Functions."
298- % name
304+ % state_machine_name
299305 )
300306 return None
307+ except StepFunctionsException :
308+ raise
301309 except Exception as e :
302310 raise StepFunctionsException (repr (e ))
303311
@@ -795,6 +803,10 @@ def _batch(self, node):
795803 metaflow_version ["production_token" ] = self .production_token
796804 env ["METAFLOW_VERSION" ] = json .dumps (metaflow_version )
797805
806+ multiflow_name = os .environ .get ("METAFLOW_MULTIFLOW_NAME" )
807+ if multiflow_name :
808+ env ["METAFLOW_MULTIFLOW_NAME" ] = multiflow_name
809+
798810 # map config values
799811 cfg_env = {param ["name" ]: param ["kv_name" ] for param in self .config_parameters }
800812 if cfg_env :
@@ -926,6 +938,9 @@ def _step_cli(self, node, paths, code_package_url, user_code_retries):
926938 entrypoint = [R .entrypoint ()]
927939 else :
928940 entrypoint = [executable , script_name ]
941+ multiflow_name = os .environ .get ("METAFLOW_MULTIFLOW_NAME" )
942+ if multiflow_name :
943+ entrypoint .append (multiflow_name )
929944
930945 # Use AWS Batch job identifier as the globally unique task identifier.
931946 task_id = "${AWS_BATCH_JOB_ID}"
0 commit comments