Skip to content

Commit 41f2db2

Browse files
author
Daniel Yoo
committed
Add support for Amazon States Language "ResultSelector" in Task, Map and Parallel States.
1 parent 08a0ed7 commit 41f2db2

File tree

8 files changed

+176
-45
lines changed

8 files changed

+176
-45
lines changed

src/stepfunctions/inputs/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#
77
# http://www.apache.org/licenses/LICENSE-2.0
88
#
9-
# or in the "license" file accompanying this file. This file is distributed
10-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
# express or implied. See the License for the specific language governing
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

15-
from stepfunctions.inputs.placeholders import Placeholder, ExecutionInput, StepInput
15+
from stepfunctions.inputs.placeholders import Placeholder, ExecutionInput, StepInput, StepResult

src/stepfunctions/inputs/placeholders.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#
77
# http://www.apache.org/licenses/LICENSE-2.0
88
#
9-
# or in the "license" file accompanying this file. This file is distributed
10-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
# express or implied. See the License for the specific language governing
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

@@ -51,11 +51,11 @@ def __init__(self, schema=None, **kwargs):
5151
self._set_schema(schema)
5252
self._make_immutable()
5353
self.json_str_template = "{}"
54-
54+
5555
self.name = kwargs.get("name")
5656
self.type = kwargs.get("type")
5757
self.parent = kwargs.get("parent")
58-
58+
5959

6060
def get(self, name, type):
6161
"""
@@ -64,11 +64,11 @@ def get(self, name, type):
6464
Args:
6565
name (str): Name of the placeholder variable.
6666
type (type): Type of the placeholder variable.
67-
67+
6868
Raises:
6969
ValueError: If placeholder variable with the same name but different type already exists.
7070
ValueError: If placeholder variable does not fit into a previously specified schema for the placeholder collection.
71-
71+
7272
Returns:
7373
Placeholder: Placeholder variable.
7474
"""
@@ -240,7 +240,7 @@ def _join_path(self, path):
240240
def to_jsonpath(self):
241241
"""
242242
Returns a JSON path representation of the placeholder variable to be used for step parameters.
243-
243+
244244
Returns:
245245
str: JSON path representation of the placeholder variable
246246
"""
@@ -252,7 +252,7 @@ class ExecutionInput(Placeholder):
252252
"""
253253
Top-level class for execution input placeholders.
254254
"""
255-
255+
256256
def __init__(self, schema=None, **kwargs):
257257
super(ExecutionInput, self).__init__(schema, **kwargs)
258258
self.json_str_template = '$$.Execution.Input{}'
@@ -268,7 +268,7 @@ def _create_variable(self, name, parent, type=None):
268268
return ExecutionInput(name=name, parent=parent, type=type)
269269
else:
270270
return ExecutionInput(name=name, parent=parent)
271-
271+
272272

273273
class StepInput(Placeholder):
274274

@@ -279,7 +279,7 @@ class StepInput(Placeholder):
279279
def __init__(self, schema=None, **kwargs):
280280
super(StepInput, self).__init__(schema, **kwargs)
281281
self.json_str_template = '${}'
282-
282+
283283
def _create_variable(self, name, parent, type=None):
284284
"""
285285
Creates a placeholder variable for Step Input.
@@ -291,3 +291,26 @@ def _create_variable(self, name, parent, type=None):
291291
return StepInput(name=name, parent=parent, type=type)
292292
else:
293293
return StepInput(name=name, parent=parent)
294+
295+
296+
class StepResult(Placeholder):
297+
298+
"""
299+
Top-level class for step result placeholders.
300+
"""
301+
302+
def __init__(self, schema=None, **kwargs):
303+
super(StepResult, self).__init__(schema, **kwargs)
304+
self.json_str_template = '${}'
305+
306+
def _create_variable(self, name, parent, type=None):
307+
"""
308+
Creates a placeholder variable for Step Result.
309+
A placeholder variable can only be created if the collection is not immutable due to a pre-specified schema.
310+
"""
311+
if self.immutable:
312+
raise ValueError("Placeholder variable does not conform to schema set for the placeholder collection.")
313+
if type:
314+
return StepResult(name=name, parent=parent, type=type)
315+
else:
316+
return StepResult(name=name, parent=parent)

src/stepfunctions/steps/compute.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self, state_id, wait_for_callback=False, **kwargs):
3232
comment (str, optional): Human-readable comment or description. (default: None)
3333
input_path (str, optional): Path applied to the state’s raw input to select some or all of it; that selection is used by the state. (default: '$')
3434
parameters (dict, optional): The value of this field becomes the effective input for the state.
35+
result_selector (dict, optional): The value of this field becomes the effective result of the state.
3536
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
3637
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$')
3738
"""
@@ -59,6 +60,7 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs):
5960
comment (str, optional): Human-readable comment or description. (default: None)
6061
input_path (str, optional): Path applied to the state’s raw input to select some or all of it; that selection is used by the state. (default: '$')
6162
parameters (dict, optional): The value of this field becomes the effective input for the state.
63+
result_selector (dict, optional): The value of this field becomes the effective result of the state.
6264
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
6365
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$')
6466
"""
@@ -86,6 +88,7 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs):
8688
comment (str, optional): Human-readable comment or description. (default: None)
8789
input_path (str, optional): Path applied to the state’s raw input to select some or all of it; that selection is used by the state. (default: '$')
8890
parameters (dict, optional): The value of this field becomes the effective input for the state.
91+
result_selector (dict, optional): The value of this field becomes the effective result of the state.
8992
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
9093
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$')
9194
"""
@@ -113,6 +116,7 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs):
113116
comment (str, optional): Human-readable comment or description. (default: None)
114117
input_path (str, optional): Path applied to the state’s raw input to select some or all of it; that selection is used by the state. (default: '$')
115118
parameters (dict, optional): The value of this field becomes the effective input for the state.
119+
result_selector (dict, optional): The value of this field becomes the effective result of the state.
116120
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
117121
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$')
118122
"""

src/stepfunctions/steps/fields.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
#
77
# http://www.apache.org/licenses/LICENSE-2.0
88
#
9-
# or in the "license" file accompanying this file. This file is distributed
10-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
# express or implied. See the License for the specific language governing
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

@@ -22,6 +22,7 @@ class Field(Enum):
2222
InputPath = 'input_path'
2323
OutputPath = 'output_path'
2424
Parameters = 'parameters'
25+
ResultSelector = 'result_selector'
2526
ResultPath = 'result_path'
2627
Next = 'next'
2728
Retry = 'retry'

0 commit comments

Comments
 (0)