Skip to content

Commit 876b26d

Browse files
authored
feat(aws-s3): add the option to not poll to the CodePipeline Action. (#1260)
1 parent 77fe077 commit 876b26d

15 files changed

+431
-34
lines changed

packages/@aws-cdk/aws-cloudtrail/README.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,29 @@ For example, to log to CloudWatch Logs
3131
import cloudtrail = require('@aws-cdk/aws-cloudtrail');
3232

3333
const trail = new cloudtrail.CloudTrail(stack, 'CloudTrail', {
34-
sendToCloudWatchLogs: true
34+
sendToCloudWatchLogs: true
3535
});
3636
```
3737

38-
This creates the same setup as above - but also logs events to a created CloudWatch Log stream. By default, the created log group has a retention period of 365 Days, but this is also configurable.
38+
This creates the same setup as above - but also logs events to a created CloudWatch Log stream.
39+
By default, the created log group has a retention period of 365 Days, but this is also configurable.
3940

40-
41-
For using CloudTrail event selector to log specific S3 events, you can use the `CloudTrailProps` configuration object
42-
43-
For example - this logs all ReadWriteEvents for the `magic-bucket` bucket:
41+
For using CloudTrail event selector to log specific S3 events,
42+
you can use the `CloudTrailProps` configuration object.
43+
Example:
4444

4545
```ts
4646
import cloudtrail = require('@aws-cdk/aws-cloudtrail');
4747

48-
const trail = new cloudtrail.CloudTrail(stack, 'MyAmazingCloudTrail')
48+
const trail = new cloudtrail.CloudTrail(stack, 'MyAmazingCloudTrail');
4949

50-
trail.addS3Filter("arn:aws:s3:::magic-bucket/"); // Adds an event selector to the bucket magic-bucket. By default, this includes management events and all operations (Read + Write)
50+
// Adds an event selector to the bucket magic-bucket.
51+
// By default, this includes management events and all operations (Read + Write)
52+
trail.addS3EventSelector(["arn:aws:s3:::magic-bucket/"]);
5153

52-
const configuration = { includeManagementEvents = false, readWriteType = ReadWriteType.All };
53-
trail.addS3Filter(["arn:aws:s3:::foo"], configuration ); // Adds an event selector to the bucket foo, with a specific configuration
54+
// Adds an event selector to the bucket foo, with a specific configuration
55+
trail.addS3EventSelector(["arn:aws:s3:::foo"], {
56+
includeManagementEvents: false,
57+
readWriteType: ReadWriteType.All,
5458
});
5559
```

packages/@aws-cdk/aws-codepipeline/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"devDependencies": {
6363
"@aws-cdk/assert": "^0.22.0",
6464
"@aws-cdk/aws-cloudformation": "^0.22.0",
65+
"@aws-cdk/aws-cloudtrail": "^0.22.0",
6566
"@aws-cdk/aws-codebuild": "^0.22.0",
6667
"@aws-cdk/aws-codecommit": "^0.22.0",
6768
"@aws-cdk/aws-codedeploy": "^0.22.0",
@@ -98,4 +99,4 @@
9899
"construct-ctor:@aws-cdk/aws-codepipeline.CrossRegionScaffoldStack.<initializer>.params[1]"
99100
]
100101
}
101-
}
102+
}

packages/@aws-cdk/aws-codepipeline/test/integ.lambda-pipeline.expected.json

+238-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"Ref": "PipelineBucketB967BD35"
146146
},
147147
"S3ObjectKey": "key",
148-
"PollForSourceChanges": true
148+
"PollForSourceChanges": false
149149
},
150150
"InputArtifacts": [],
151151
"Name": "Source",
@@ -188,6 +188,66 @@
188188
"PipelineRoleDefaultPolicyC7A05455"
189189
]
190190
},
191+
"PipelineEventsRole46BEEA7C": {
192+
"Type": "AWS::IAM::Role",
193+
"Properties": {
194+
"AssumeRolePolicyDocument": {
195+
"Statement": [
196+
{
197+
"Action": "sts:AssumeRole",
198+
"Effect": "Allow",
199+
"Principal": {
200+
"Service": "events.amazonaws.com"
201+
}
202+
}
203+
],
204+
"Version": "2012-10-17"
205+
}
206+
}
207+
},
208+
"PipelineEventsRoleDefaultPolicyFF4FCCE0": {
209+
"Type": "AWS::IAM::Policy",
210+
"Properties": {
211+
"PolicyDocument": {
212+
"Statement": [
213+
{
214+
"Action": "codepipeline:StartPipelineExecution",
215+
"Effect": "Allow",
216+
"Resource": {
217+
"Fn::Join": [
218+
"",
219+
[
220+
"arn:",
221+
{
222+
"Ref": "AWS::Partition"
223+
},
224+
":codepipeline:",
225+
{
226+
"Ref": "AWS::Region"
227+
},
228+
":",
229+
{
230+
"Ref": "AWS::AccountId"
231+
},
232+
":",
233+
{
234+
"Ref": "PipelineC660917D"
235+
}
236+
]
237+
]
238+
}
239+
}
240+
],
241+
"Version": "2012-10-17"
242+
},
243+
"PolicyName": "PipelineEventsRoleDefaultPolicyFF4FCCE0",
244+
"Roles": [
245+
{
246+
"Ref": "PipelineEventsRole46BEEA7C"
247+
}
248+
]
249+
}
250+
},
191251
"PipelineBucketB967BD35": {
192252
"Type": "AWS::S3::Bucket",
193253
"Properties": {
@@ -196,6 +256,182 @@
196256
}
197257
}
198258
},
259+
"PipelineBucketawscdkcodepipelinelambdaPipeline87A4B3D3SourceEventRuleCE4D4505": {
260+
"Type": "AWS::Events::Rule",
261+
"Properties": {
262+
"EventPattern": {
263+
"source": [
264+
"aws.s3"
265+
],
266+
"detail-type": [
267+
"AWS API Call via CloudTrail"
268+
],
269+
"detail": {
270+
"eventSource": [
271+
"s3.amazonaws.com"
272+
],
273+
"eventName": [
274+
"PutObject"
275+
],
276+
"resources": {
277+
"ARN": [
278+
{
279+
"Fn::Join": [
280+
"",
281+
[
282+
{
283+
"Fn::GetAtt": [
284+
"PipelineBucketB967BD35",
285+
"Arn"
286+
]
287+
},
288+
"/key"
289+
]
290+
]
291+
}
292+
]
293+
}
294+
}
295+
},
296+
"State": "ENABLED",
297+
"Targets": [
298+
{
299+
"Arn": {
300+
"Fn::Join": [
301+
"",
302+
[
303+
"arn:",
304+
{
305+
"Ref": "AWS::Partition"
306+
},
307+
":codepipeline:",
308+
{
309+
"Ref": "AWS::Region"
310+
},
311+
":",
312+
{
313+
"Ref": "AWS::AccountId"
314+
},
315+
":",
316+
{
317+
"Ref": "PipelineC660917D"
318+
}
319+
]
320+
]
321+
},
322+
"Id": "Pipeline",
323+
"RoleArn": {
324+
"Fn::GetAtt": [
325+
"PipelineEventsRole46BEEA7C",
326+
"Arn"
327+
]
328+
}
329+
}
330+
]
331+
}
332+
},
333+
"CloudTrailS310CD22F2": {
334+
"Type": "AWS::S3::Bucket",
335+
"DeletionPolicy": "Retain"
336+
},
337+
"CloudTrailS3PolicyEA49A03E": {
338+
"Type": "AWS::S3::BucketPolicy",
339+
"Properties": {
340+
"Bucket": {
341+
"Ref": "CloudTrailS310CD22F2"
342+
},
343+
"PolicyDocument": {
344+
"Statement": [
345+
{
346+
"Action": "s3:GetBucketAcl",
347+
"Effect": "Allow",
348+
"Principal": {
349+
"Service": "cloudtrail.amazonaws.com"
350+
},
351+
"Resource": {
352+
"Fn::GetAtt": [
353+
"CloudTrailS310CD22F2",
354+
"Arn"
355+
]
356+
}
357+
},
358+
{
359+
"Action": "s3:PutObject",
360+
"Condition": {
361+
"StringEquals": {
362+
"s3:x-amz-acl": "bucket-owner-full-control"
363+
}
364+
},
365+
"Effect": "Allow",
366+
"Principal": {
367+
"Service": "cloudtrail.amazonaws.com"
368+
},
369+
"Resource": {
370+
"Fn::Join": [
371+
"",
372+
[
373+
{
374+
"Fn::GetAtt": [
375+
"CloudTrailS310CD22F2",
376+
"Arn"
377+
]
378+
},
379+
"/AWSLogs/",
380+
{
381+
"Ref": "AWS::AccountId"
382+
},
383+
"/*"
384+
]
385+
]
386+
}
387+
}
388+
],
389+
"Version": "2012-10-17"
390+
}
391+
}
392+
},
393+
"CloudTrailA62D711D": {
394+
"Type": "AWS::CloudTrail::Trail",
395+
"Properties": {
396+
"IsLogging": true,
397+
"S3BucketName": {
398+
"Ref": "CloudTrailS310CD22F2"
399+
},
400+
"EnableLogFileValidation": true,
401+
"EventSelectors": [
402+
{
403+
"DataResources": [
404+
{
405+
"Type": "AWS::S3::Object",
406+
"Values": [
407+
{
408+
"Fn::Join": [
409+
"",
410+
[
411+
{
412+
"Fn::GetAtt": [
413+
"PipelineBucketB967BD35",
414+
"Arn"
415+
]
416+
},
417+
"/key"
418+
]
419+
]
420+
}
421+
]
422+
}
423+
],
424+
"IncludeManagementEvents": false,
425+
"ReadWriteType": "WriteOnly"
426+
}
427+
],
428+
"IncludeGlobalServiceEvents": true,
429+
"IsMultiRegionTrail": true
430+
},
431+
"DependsOn": [
432+
"CloudTrailS3PolicyEA49A03E"
433+
]
434+
},
199435
"LambdaFunServiceRoleF0979767": {
200436
"Type": "AWS::IAM::Role",
201437
"Properties": {
@@ -272,4 +508,4 @@
272508
]
273509
}
274510
}
275-
}
511+
}

packages/@aws-cdk/aws-codepipeline/test/integ.lambda-pipeline.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import cloudtrail = require('@aws-cdk/aws-cloudtrail');
12
import lambda = require('@aws-cdk/aws-lambda');
23
import s3 = require('@aws-cdk/aws-s3');
34
import cdk = require('@aws-cdk/cdk');
@@ -14,11 +15,15 @@ const bucket = new s3.Bucket(stack, 'PipelineBucket', {
1415
versioned: true,
1516
removalPolicy: cdk.RemovalPolicy.Destroy,
1617
});
18+
const key = 'key';
19+
const trail = new cloudtrail.CloudTrail(stack, 'CloudTrail');
20+
trail.addS3EventSelector([bucket.arnForObjects(key)], cloudtrail.ReadWriteType.WriteOnly);
1721
new s3.PipelineSourceAction(stack, 'Source', {
1822
stage: sourceStage,
1923
outputArtifactName: 'SourceArtifact',
2024
bucket,
21-
bucketKey: 'key',
25+
bucketKey: key,
26+
pollForSourceChanges: false,
2227
});
2328

2429
const lambdaFun = new lambda.Function(stack, 'LambdaFun', {

packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-cfn-cross-region.expected.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@
161161
"S3Bucket": {
162162
"Ref": "MyBucketF68F3FF0"
163163
},
164-
"S3ObjectKey": "some/path",
165-
"PollForSourceChanges": true
164+
"S3ObjectKey": "some/path"
166165
},
167166
"InputArtifacts": [],
168167
"Name": "S3",
@@ -245,4 +244,4 @@
245244
}
246245
}
247246
}
248-
}
247+
}

packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-cfn.expected.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@
173173
"S3Bucket": {
174174
"Ref": "PipelineBucketB967BD35"
175175
},
176-
"S3ObjectKey": "key",
177-
"PollForSourceChanges": true
176+
"S3ObjectKey": "key"
178177
},
179178
"InputArtifacts": [],
180179
"Name": "Source",

packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-build-multiple-inputs-outputs.expected.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@
275275
"S3Bucket": {
276276
"Ref": "MyBucketF68F3FF0"
277277
},
278-
"S3ObjectKey": "some/path",
279-
"PollForSourceChanges": true
278+
"S3ObjectKey": "some/path"
280279
},
281280
"InputArtifacts": [],
282281
"Name": "Source2",

packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-deploy.expected.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@
284284
"S3Bucket": {
285285
"Ref": "CodeDeployPipelineIntegTest9F618D61"
286286
},
287-
"S3ObjectKey": "application.zip",
288-
"PollForSourceChanges": true
287+
"S3ObjectKey": "application.zip"
289288
},
290289
"InputArtifacts": [],
291290
"Name": "S3Source",
@@ -336,4 +335,4 @@
336335
]
337336
}
338337
}
339-
}
338+
}

0 commit comments

Comments
 (0)