@@ -11,7 +11,9 @@ export = {
11
11
'Lambda invoke Action' : {
12
12
'properly serializes the object passed in userParameters' ( test : Test ) {
13
13
const stack = stackIncludingLambdaInvokeCodePipeline ( {
14
- key : 1234 ,
14
+ userParams : {
15
+ key : 1234 ,
16
+ } ,
15
17
} ) ;
16
18
17
19
expect ( stack ) . to ( haveResourceLike ( 'AWS::CodePipeline::Pipeline' , {
@@ -34,7 +36,9 @@ export = {
34
36
35
37
'properly resolves any Tokens passed in userParameters' ( test : Test ) {
36
38
const stack = stackIncludingLambdaInvokeCodePipeline ( {
37
- key : Lazy . stringValue ( { produce : ( ) => Aws . REGION } ) ,
39
+ userParams : {
40
+ key : Lazy . stringValue ( { produce : ( ) => Aws . REGION } ) ,
41
+ } ,
38
42
} ) ;
39
43
40
44
expect ( stack ) . to ( haveResourceLike ( 'AWS::CodePipeline::Pipeline' , {
@@ -68,7 +72,9 @@ export = {
68
72
69
73
'properly resolves any stringified Tokens passed in userParameters' ( test : Test ) {
70
74
const stack = stackIncludingLambdaInvokeCodePipeline ( {
71
- key : Token . asString ( null ) ,
75
+ userParams : {
76
+ key : Token . asString ( null ) ,
77
+ } ,
72
78
} ) ;
73
79
74
80
expect ( stack ) . to ( haveResourceLike ( 'AWS::CodePipeline::Pipeline' , {
@@ -88,10 +94,152 @@ export = {
88
94
89
95
test . done ( ) ;
90
96
} ,
97
+
98
+ "assigns the Action's Role with read permissions to the Bucket if it has only inputs" ( test : Test ) {
99
+ const stack = stackIncludingLambdaInvokeCodePipeline ( {
100
+ lambdaInput : new codepipeline . Artifact ( ) ,
101
+ } ) ;
102
+
103
+ expect ( stack ) . to ( haveResourceLike ( 'AWS::IAM::Policy' , {
104
+ "PolicyDocument" : {
105
+ "Statement" : [
106
+ {
107
+ "Action" : "lambda:ListFunctions" ,
108
+ "Resource" : "*" ,
109
+ "Effect" : "Allow" ,
110
+ } ,
111
+ {
112
+ "Action" : "lambda:InvokeFunction" ,
113
+ "Effect" : "Allow" ,
114
+ } ,
115
+ {
116
+ "Action" : [
117
+ "s3:GetObject*" ,
118
+ "s3:GetBucket*" ,
119
+ "s3:List*" ,
120
+ ] ,
121
+ "Effect" : "Allow" ,
122
+ } ,
123
+ {
124
+ "Action" : [
125
+ "kms:Decrypt" ,
126
+ "kms:DescribeKey" ,
127
+ ] ,
128
+ "Effect" : "Allow" ,
129
+ } ,
130
+ ] ,
131
+ } ,
132
+ } ) ) ;
133
+
134
+ test . done ( ) ;
135
+ } ,
136
+
137
+ "assigns the Action's Role with write permissions to the Bucket if it has only outputs" ( test : Test ) {
138
+ const stack = stackIncludingLambdaInvokeCodePipeline ( {
139
+ lambdaOutput : new codepipeline . Artifact ( ) ,
140
+ // no input to the Lambda Action - we want write permissions only in this case
141
+ } ) ;
142
+
143
+ expect ( stack ) . to ( haveResourceLike ( 'AWS::IAM::Policy' , {
144
+ "PolicyDocument" : {
145
+ "Statement" : [
146
+ {
147
+ "Action" : "lambda:ListFunctions" ,
148
+ "Resource" : "*" ,
149
+ "Effect" : "Allow" ,
150
+ } ,
151
+ {
152
+ "Action" : "lambda:InvokeFunction" ,
153
+ "Effect" : "Allow" ,
154
+ } ,
155
+ {
156
+ "Action" : [
157
+ "s3:DeleteObject*" ,
158
+ "s3:PutObject*" ,
159
+ "s3:Abort*" ,
160
+ ] ,
161
+ "Effect" : "Allow" ,
162
+ } ,
163
+ {
164
+ "Action" : [
165
+ "kms:Encrypt" ,
166
+ "kms:ReEncrypt*" ,
167
+ "kms:GenerateDataKey*" ,
168
+ ] ,
169
+ "Effect" : "Allow" ,
170
+ } ,
171
+ ] ,
172
+ } ,
173
+ } ) ) ;
174
+
175
+ test . done ( ) ;
176
+ } ,
177
+
178
+ "assigns the Action's Role with read-write permissions to the Bucket if it has both inputs and outputs" ( test : Test ) {
179
+ const stack = stackIncludingLambdaInvokeCodePipeline ( {
180
+ lambdaInput : new codepipeline . Artifact ( ) ,
181
+ lambdaOutput : new codepipeline . Artifact ( ) ,
182
+ } ) ;
183
+
184
+ expect ( stack ) . to ( haveResourceLike ( 'AWS::IAM::Policy' , {
185
+ "PolicyDocument" : {
186
+ "Statement" : [
187
+ {
188
+ "Action" : "lambda:ListFunctions" ,
189
+ "Resource" : "*" ,
190
+ "Effect" : "Allow" ,
191
+ } ,
192
+ {
193
+ "Action" : "lambda:InvokeFunction" ,
194
+ "Effect" : "Allow" ,
195
+ } ,
196
+ {
197
+ "Action" : [
198
+ "s3:GetObject*" ,
199
+ "s3:GetBucket*" ,
200
+ "s3:List*" ,
201
+ ] ,
202
+ "Effect" : "Allow" ,
203
+ } ,
204
+ {
205
+ "Action" : [
206
+ "kms:Decrypt" ,
207
+ "kms:DescribeKey" ,
208
+ ] ,
209
+ "Effect" : "Allow" ,
210
+ } ,
211
+ {
212
+ "Action" : [
213
+ "s3:DeleteObject*" ,
214
+ "s3:PutObject*" ,
215
+ "s3:Abort*" ,
216
+ ] ,
217
+ "Effect" : "Allow" ,
218
+ } ,
219
+ {
220
+ "Action" : [
221
+ "kms:Encrypt" ,
222
+ "kms:ReEncrypt*" ,
223
+ "kms:GenerateDataKey*" ,
224
+ ] ,
225
+ "Effect" : "Allow" ,
226
+ } ,
227
+ ] ,
228
+ } ,
229
+ } ) ) ;
230
+
231
+ test . done ( ) ;
232
+ } ,
91
233
} ,
92
234
} ;
93
235
94
- function stackIncludingLambdaInvokeCodePipeline ( userParams : { [ key : string ] : any } ) {
236
+ interface HelperProps {
237
+ readonly userParams ?: { [ key : string ] : any } ;
238
+ readonly lambdaInput ?: codepipeline . Artifact ;
239
+ readonly lambdaOutput ?: codepipeline . Artifact ;
240
+ }
241
+
242
+ function stackIncludingLambdaInvokeCodePipeline ( props : HelperProps ) {
95
243
const stack = new Stack ( ) ;
96
244
97
245
new codepipeline . Pipeline ( stack , 'Pipeline' , {
@@ -101,7 +249,7 @@ function stackIncludingLambdaInvokeCodePipeline(userParams: { [key: string]: any
101
249
actions : [
102
250
new cpactions . GitHubSourceAction ( {
103
251
actionName : 'GitHub' ,
104
- output : new codepipeline . Artifact ( ) ,
252
+ output : props . lambdaInput || new codepipeline . Artifact ( ) ,
105
253
oauthToken : SecretValue . plainText ( 'secret' ) ,
106
254
owner : 'awslabs' ,
107
255
repo : 'aws-cdk' ,
@@ -118,7 +266,9 @@ function stackIncludingLambdaInvokeCodePipeline(userParams: { [key: string]: any
118
266
handler : 'index.handler' ,
119
267
runtime : lambda . Runtime . NODEJS_8_10 ,
120
268
} ) ,
121
- userParameters : userParams ,
269
+ userParameters : props . userParams ,
270
+ inputs : props . lambdaInput ? [ props . lambdaInput ] : undefined ,
271
+ outputs : props . lambdaOutput ? [ props . lambdaOutput ] : undefined ,
122
272
} ) ,
123
273
] ,
124
274
} ,
0 commit comments