File tree 2 files changed +66
-4
lines changed
packages/@aws-cdk/aws-stepfunctions
2 files changed +66
-4
lines changed Original file line number Diff line number Diff line change @@ -37,20 +37,39 @@ export interface StateMachineProps {
37
37
}
38
38
39
39
/**
40
- * Define a StepFunctions State Machine
40
+ * A new or imported state machine.
41
41
*/
42
- export class StateMachine extends Resource implements IStateMachine {
42
+ abstract class StateMachineBase extends Resource implements IStateMachine {
43
43
/**
44
44
* Import a state machine
45
45
*/
46
46
public static fromStateMachineArn ( scope : Construct , id : string , stateMachineArn : string ) : IStateMachine {
47
- class Import extends Resource implements IStateMachine {
47
+ class Import extends StateMachineBase {
48
48
public readonly stateMachineArn = stateMachineArn ;
49
49
}
50
50
51
51
return new Import ( scope , id ) ;
52
52
}
53
53
54
+ public abstract readonly stateMachineArn : string ;
55
+
56
+ /**
57
+ * Grant the given identity permissions to start an execution of this state
58
+ * machine.
59
+ */
60
+ public grantStartExecution ( identity : iam . IGrantable ) : iam . Grant {
61
+ return iam . Grant . addToPrincipal ( {
62
+ grantee : identity ,
63
+ actions : [ 'states:StartExecution' ] ,
64
+ resourceArns : [ this . stateMachineArn ]
65
+ } ) ;
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Define a StepFunctions State Machine
71
+ */
72
+ export class StateMachine extends StateMachineBase {
54
73
/**
55
74
* Execution role of this state machine
56
75
*/
Original file line number Diff line number Diff line change @@ -129,4 +129,47 @@ export = {
129
129
test . done ( ) ;
130
130
} ,
131
131
132
- } ;
132
+ 'Can grant start execution to a role' ( test : Test ) {
133
+ // GIVEN
134
+ const stack = new cdk . Stack ( ) ;
135
+ const task = new stepfunctions . Task ( stack , 'Task' , {
136
+ task : {
137
+ bind : ( ) => ( { resourceArn : 'resource' } )
138
+ }
139
+ } ) ;
140
+ const stateMachine = new stepfunctions . StateMachine ( stack , 'StateMachine' , {
141
+ definition : task
142
+ } ) ;
143
+ const role = new iam . Role ( stack , 'Role' , {
144
+ assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' )
145
+ } ) ;
146
+
147
+ // WHEN
148
+ stateMachine . grantStartExecution ( role ) ;
149
+
150
+ // THEN
151
+ expect ( stack ) . to ( haveResource ( 'AWS::IAM::Policy' , {
152
+ PolicyDocument : {
153
+ Statement : [
154
+ {
155
+ Action : 'states:StartExecution' ,
156
+ Effect : 'Allow' ,
157
+ Resource : {
158
+ Ref : 'StateMachine2E01A3A5'
159
+ }
160
+ }
161
+ ] ,
162
+ Version : '2012-10-17' ,
163
+ } ,
164
+ PolicyName : 'RoleDefaultPolicy5FFB7DAB' ,
165
+ Roles : [
166
+ {
167
+ Ref : 'Role1ABCC5F0'
168
+ }
169
+ ]
170
+ } ) ) ;
171
+
172
+ test . done ( ) ;
173
+ }
174
+
175
+ } ;
You can’t perform that action at this time.
0 commit comments