Skip to content

Commit c05c90f

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

File tree

8 files changed

+167
-36
lines changed

8 files changed

+167
-36
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
@@ -57,6 +57,7 @@ def __init__(self, state_id, wait_for_callback=False, **kwargs):
5757
comment (str, optional): Human-readable comment or description. (default: None)
5858
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: '$')
5959
parameters (dict, optional): The value of this field becomes the effective input for the state.
60+
result_selector (dict, optional): The value of this field becomes the effective result of the state.
6061
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
6162
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: '$')
6263
"""
@@ -98,6 +99,7 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs):
9899
comment (str, optional): Human-readable comment or description. (default: None)
99100
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: '$')
100101
parameters (dict, optional): The value of this field becomes the effective input for the state.
102+
result_selector (dict, optional): The value of this field becomes the effective result of the state.
101103
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
102104
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: '$')
103105
"""
@@ -138,6 +140,7 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs):
138140
comment (str, optional): Human-readable comment or description. (default: None)
139141
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: '$')
140142
parameters (dict, optional): The value of this field becomes the effective input for the state.
143+
result_selector (dict, optional): The value of this field becomes the effective result of the state.
141144
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
142145
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: '$')
143146
"""
@@ -178,6 +181,7 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs):
178181
comment (str, optional): Human-readable comment or description. (default: None)
179182
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: '$')
180183
parameters (dict, optional): The value of this field becomes the effective input for the state.
184+
result_selector (dict, optional): The value of this field becomes the effective result of the state.
181185
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
182186
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: '$')
183187
"""

src/stepfunctions/steps/fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)