Skip to content

Commit fe9ee7d

Browse files
committed
Allow setting Lambda role
Unfortunately, boto2 doesn't support passing lambdaRole; we must override two of its methods (register type and start workflow). Signed-off-by: Yves Bastide <yves@botify.com>
1 parent f2908ff commit fe9ee7d

File tree

4 files changed

+238
-17
lines changed

4 files changed

+238
-17
lines changed

simpleflow/command.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ def transform_input(wf_input):
144144
type=comma_separated_list,
145145
required=False,
146146
help='Tags for the workflow execution.')
147+
@click.option('--lambda-role',
148+
required=False,
149+
help='Lambda role.')
147150
@click.option('--decision-tasks-timeout',
148151
required=False,
149152
help='Timeout for the decision tasks.')
@@ -168,6 +171,7 @@ def start_workflow(workflow,
168171
task_list,
169172
execution_timeout,
170173
tags,
174+
lambda_role,
171175
decision_tasks_timeout,
172176
input,
173177
input_file,
@@ -193,6 +197,7 @@ def start_workflow(workflow,
193197
execution_timeout=execution_timeout,
194198
input=wf_input,
195199
tag_list=tags,
200+
lambda_role=lambda_role or workflow_class.lambda_role,
196201
decision_tasks_timeout=decision_tasks_timeout,
197202
)
198203
print('{workflow_id} {run_id}'.format(
@@ -449,6 +454,9 @@ def create_unique_task_list(workflow_id=''):
449454
type=comma_separated_list,
450455
required=False,
451456
help='Tags identifying the workflow execution.')
457+
@click.option('--lambda-role',
458+
required=False,
459+
help='Lambda role.')
452460
@click.option('--decision-tasks-timeout',
453461
required=False,
454462
help='Decision tasks timeout.')
@@ -483,6 +491,7 @@ def standalone(context,
483491
workflow_id,
484492
execution_timeout,
485493
tags,
494+
lambda_role,
486495
decision_tasks_timeout,
487496
input,
488497
input_file,
@@ -569,6 +578,7 @@ def standalone(context,
569578
task_list,
570579
execution_timeout,
571580
tags,
581+
lambda_role,
572582
decision_tasks_timeout,
573583
json_dumps(wf_input),
574584
None,

simpleflow/workflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Workflow(Submittable):
3030
version = None
3131
task_list = None
3232
task_priority = None
33+
lambda_role = None
3334

3435
def __init__(self, executor):
3536
self._executor = executor

swf/models/decision/workflow.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ def terminate(self, reason=None, details=None):
5757
def continue_as_new(self, child_policy=None,
5858
execution_timeout=None, task_timeout=None,
5959
input=None, tag_list=None, task_list=None,
60+
lambda_role=None,
6061
workflow_type_version=None):
61-
"""Coninue as new workflow execution decision builder
62+
"""Continue as new workflow execution decision builder
6263
:param child_policy: specifies the policy to use for the
6364
child workflow executions of the new execution
6465
:type child_policy: CHILD_POLICIES.{TERMINATE | REQUEST_CANCEL | ABANDON}
@@ -75,6 +76,9 @@ def continue_as_new(self, child_policy=None,
7576
:param task_list: task list name
7677
:type task_list: str
7778
79+
:param lambda_role: Lambda role
80+
:type lambda_role: str
81+
7882
:param task_timeout: maximum duration of decision tasks for the new workflow execution
7983
:type task_timeout: str
8084
@@ -91,6 +95,7 @@ def continue_as_new(self, child_policy=None,
9195
'input': input,
9296
'tagList': tag_list,
9397
'taskList': task_list,
98+
'lambdaRole': lambda_role,
9499
'workflowTypeVersion': workflow_type_version,
95100
})
96101

@@ -101,7 +106,7 @@ class ChildWorkflowExecutionDecision(Decision):
101106
@decision_action
102107
def start(self, workflow_type, workflow_id, child_policy=CHILD_POLICIES.TERMINATE,
103108
execution_timeout='300', task_timeout='300', control=None,
104-
input=None, tag_list=None, task_list=None):
109+
input=None, tag_list=None, task_list=None, lambda_role=None):
105110
"""Child workflow execution decision builder
106111
107112
:param workflow_type: workflow type to start
@@ -117,6 +122,12 @@ def start(self, workflow_type, workflow_id, child_policy=CHILD_POLICIES.TERMINAT
117122
:param execution_timeout: specifies the total duration for this workflow execution
118123
:type execution_timeout: str
119124
125+
:param task_timeout: maximum duration of decision tasks for the child workflow execution
126+
:type task_timeout: str
127+
128+
:param control: data attached to the event that can be used by the decider in subsequent workflow tasks
129+
:type control: Optional[str]
130+
120131
:param input: The input provided to the child workflow execution
121132
:type input: str
122133
@@ -126,8 +137,8 @@ def start(self, workflow_type, workflow_id, child_policy=CHILD_POLICIES.TERMINAT
126137
:param task_list: task list name
127138
:type task_list: str
128139
129-
:param task_timeout: maximum duration of decision tasks for the child workflow execution
130-
:type task_timeout: str
140+
:param lambda_role: workflow lambda role
141+
:type lambda_role: Optional[str]
131142
132143
"""
133144
if input is not None:
@@ -143,6 +154,7 @@ def start(self, workflow_type, workflow_id, child_policy=CHILD_POLICIES.TERMINAT
143154
'taskList': {
144155
'name': task_list,
145156
},
157+
'lambdaRole': lambda_role,
146158
'workflowId': workflow_id,
147159
'workflowType': {
148160
'name': workflow_type.name,

0 commit comments

Comments
 (0)