in samcli/lib/remote_invoke/stepfunctions_invoke_executors.py [0:0]
def _execute_action(self, payload: str) -> RemoteInvokeIterableResponseType:
"""
Calls "start_execution" method to start the execution and waits
for the execution to complete using the "describe_execution" method
Parameters
----------
payload: str
The input which is passed to the execution
Yields
------
RemoteInvokeIterableResponseType
Response that is consumed by remote invoke consumers after execution
"""
self.request_parameters[INPUT] = payload
self.request_parameters[STATE_MACHINE_ARN] = self._state_machine_arn
LOG.debug(
"Calling stepfunctions_client.start_execution with name:%s, input:%s, stateMachineArn:%s",
self.request_parameters["name"],
payload,
self._state_machine_arn,
)
try:
start_execution_response = self._stepfunctions_client.start_execution(**self.request_parameters)
execution_arn = start_execution_response["executionArn"]
execution_status = RUNNING
while execution_status == RUNNING:
describe_execution_response = cast(
dict, self._stepfunctions_client.describe_execution(executionArn=execution_arn)
)
execution_status = describe_execution_response["status"]
LOG.debug("ExecutionArn: %s, status: %s", execution_arn, execution_status)
# Sleep to avoid throttling the API for longer executions
time.sleep(SFN_EXECUTION_WAIT_TIME)
if self._remote_output_format == RemoteInvokeOutputFormat.JSON:
yield RemoteInvokeResponse(describe_execution_response)
if self._remote_output_format == RemoteInvokeOutputFormat.TEXT:
output_data = describe_execution_response.get("output", "")
error_data = describe_execution_response.get("error", "")
if output_data:
yield RemoteInvokeResponse(output_data)
return
if error_data:
error_cause = describe_execution_response.get("cause", "")
yield RemoteInvokeLogOutput(
f"The execution failed due to the error: {error_data} and cause: {error_cause}"
)
return
except ParamValidationError as param_val_ex:
raise InvalidResourceBotoParameterException(
f"Invalid parameter key provided."
f" {str(param_val_ex).replace(f'{STATE_MACHINE_ARN}, ', '').replace(f'{INPUT}, ', '')}"
)
except ClientError as client_ex:
raise ErrorBotoApiCallException(client_ex) from client_ex