Placeholders

Once defined, a workflow is static unless you update it explicitly. But, you can pass input to workflow executions. You can have dynamic values that you use in the parameters fields of the steps in your workflow. For this, the AWS Step Functions Data Science SDK provides a way to define placeholders to pass around when you create your workflow. There are 2 mechanisms for passing dynamic values in a workflow.

The first mechanism is a global input to the workflow execution. This input is accessible to all the steps in the workflow. The SDK provides stepfunctions.inputs.ExecutionInput() to define the schema for this input, and to access the values in your workflow.

# Create an instance of ExecutionInput class, and define a schema. Defining
# a schema is optional, but it is a good practice

my_execution_input = ExecutionInput(schema={
    'myDynamicInput': str
})

lambda_state = LambdaStep(
    state_id="MyLambdaStep",
    parameters={
        "FunctionName": "MyLambda",
        "Payload": {
           "input": my_execution_input["myDynamicInput"] #Use as a
                                                         #Python dictionary
        }
    }
)

# Workflow is created with the placeholders
workflow = Workflow(
    name='MyLambdaWorkflowWithGlobalInput',
    definition=lambda_state,
    role=workflow_execution_role,
    execution_input=my_execution_input # Provide the execution_input when
                                       # defining your workflow
)

# Create the workflow on AWS Step Functions
workflow.create()

# The placeholder is assigned a value during execution. The SDK will
# verify that all placeholder values are assigned values, and that
# these values are of the expected type based on the defined schema
# before the execution starts.

workflow.execute(inputs={'myDynamicInput': "WorldHello"})

The second mechanism is for passing dynamic values from one step to the next step. The output of one step becomes the input of the next step. The SDK provides the stepfunctions.inputs.StepInput() class for this.

By default, each step has an output method stepfunctions.steps.states.State.output() that returns the placeholder output for that step.

lambda_state_first = LambdaStep(
    state_id="MyFirstLambdaStep",
    parameters={
        "FunctionName": "MakeApiCall",
        "Payload": {
          "input": "20192312"
          }
        }
      )

lambda_state_second = LambdaStep(
      state_id="MySecondLambdaStep",
      parameters={
        "FunctionName": "ProcessCallResult",
        "Payload": {
          "input": lambda_state_first.output()["Response"] #Use as a Python dictionary
          }
        }
      )

definition = Chain([lambda_state_first, lambda_state_second])
class stepfunctions.inputs.Placeholder(schema=None, **kwargs)

Bases: object

A collection of Placeholder variables.

Parameters:

schema (dict, optional) –

Schema for the placeholder collection. (default: None) Example below:

{
    'ModelName': str,
    'JobName': str,
    'Hyperparameters': {
        'tol': float
    }
}

Keyword Arguments:
 
  • name (str, optional) – Name of the placeholder variable. (default: None)
  • type (type, optional) – Type of the placeholder variable. (default: None)
  • parent (Placeholder, optional) – Parent variable for a placeholder variable. (default: None)
get(name, type)

Create a placeholder variable with an associated type.

Parameters:
  • name (str) – Name of the placeholder variable.
  • type (type) – Type of the placeholder variable.
Raises:
  • ValueError – If placeholder variable with the same name but different type already exists.
  • ValueError – If placeholder variable does not fit into a previously specified schema for the placeholder collection.
Returns:

Placeholder variable.

Return type:

Placeholder

get_schema_as_dict()

Generate a schema for the placeholder collection as a Python dictionary.

Returns:Placeholder collection schema.
Return type:dict
get_schema_as_json(pretty=False)

Generate a schema for the placeholder collection as a JSON formatted string.

Parameters:pretty (bool, optional) – Boolean flag set to True if JSON string should be prettified. False, otherwise. (default: False)
Returns:JSON formatted string representation of the block.
Return type:str
contains(placeholder)

Check if the placeholder collection contains the specified placeholder variable.

Parameters:placeholder (Placeholder) – Placeholder variable to search for, in the collection.
Returns:True if placeholder variable was found in the collection. False, otherwise.
Return type:bool
validate(input)

Validate a specified input against the placeholder collection schema.

Parameters:input (dict) – Input to validate against the placeholder collection schema.
Returns:
Named tuple with the keys:
valid (Boolean): Representing the result of validation , keys_missing (list(str)): List of keys missing in the input , keys_type_mismatch (list(str), type, type): List of tuples with key name, expected type, and provided type.
Return type:ValidationResult
to_jsonpath()

Returns a JSON path representation of the placeholder variable to be used for step parameters.

Returns:JSON path representation of the placeholder variable
Return type:str
class stepfunctions.inputs.ExecutionInput(schema=None, **kwargs)

Bases: stepfunctions.inputs.placeholders.Placeholder

Top-level class for execution input placeholders.

contains(placeholder)

Check if the placeholder collection contains the specified placeholder variable.

Parameters:placeholder (Placeholder) – Placeholder variable to search for, in the collection.
Returns:True if placeholder variable was found in the collection. False, otherwise.
Return type:bool
get(name, type)

Create a placeholder variable with an associated type.

Parameters:
  • name (str) – Name of the placeholder variable.
  • type (type) – Type of the placeholder variable.
Raises:
  • ValueError – If placeholder variable with the same name but different type already exists.
  • ValueError – If placeholder variable does not fit into a previously specified schema for the placeholder collection.
Returns:

Placeholder variable.

Return type:

Placeholder

get_schema_as_dict()

Generate a schema for the placeholder collection as a Python dictionary.

Returns:Placeholder collection schema.
Return type:dict
get_schema_as_json(pretty=False)

Generate a schema for the placeholder collection as a JSON formatted string.

Parameters:pretty (bool, optional) – Boolean flag set to True if JSON string should be prettified. False, otherwise. (default: False)
Returns:JSON formatted string representation of the block.
Return type:str
to_jsonpath()

Returns a JSON path representation of the placeholder variable to be used for step parameters.

Returns:JSON path representation of the placeholder variable
Return type:str
validate(input)

Validate a specified input against the placeholder collection schema.

Parameters:input (dict) – Input to validate against the placeholder collection schema.
Returns:
Named tuple with the keys:
valid (Boolean): Representing the result of validation , keys_missing (list(str)): List of keys missing in the input , keys_type_mismatch (list(str), type, type): List of tuples with key name, expected type, and provided type.
Return type:ValidationResult
class stepfunctions.inputs.StepInput(schema=None, **kwargs)

Bases: stepfunctions.inputs.placeholders.Placeholder

Top-level class for step input placeholders.

contains(placeholder)

Check if the placeholder collection contains the specified placeholder variable.

Parameters:placeholder (Placeholder) – Placeholder variable to search for, in the collection.
Returns:True if placeholder variable was found in the collection. False, otherwise.
Return type:bool
get(name, type)

Create a placeholder variable with an associated type.

Parameters:
  • name (str) – Name of the placeholder variable.
  • type (type) – Type of the placeholder variable.
Raises:
  • ValueError – If placeholder variable with the same name but different type already exists.
  • ValueError – If placeholder variable does not fit into a previously specified schema for the placeholder collection.
Returns:

Placeholder variable.

Return type:

Placeholder

get_schema_as_dict()

Generate a schema for the placeholder collection as a Python dictionary.

Returns:Placeholder collection schema.
Return type:dict
get_schema_as_json(pretty=False)

Generate a schema for the placeholder collection as a JSON formatted string.

Parameters:pretty (bool, optional) – Boolean flag set to True if JSON string should be prettified. False, otherwise. (default: False)
Returns:JSON formatted string representation of the block.
Return type:str
to_jsonpath()

Returns a JSON path representation of the placeholder variable to be used for step parameters.

Returns:JSON path representation of the placeholder variable
Return type:str
validate(input)

Validate a specified input against the placeholder collection schema.

Parameters:input (dict) – Input to validate against the placeholder collection schema.
Returns:
Named tuple with the keys:
valid (Boolean): Representing the result of validation , keys_missing (list(str)): List of keys missing in the input , keys_type_mismatch (list(str), type, type): List of tuples with key name, expected type, and provided type.
Return type:ValidationResult