Skip to content

Commit 5b78852

Browse files
Merge branch 'master' into issue_8277
2 parents f2e0c4e + 44f2423 commit 5b78852

37 files changed

+732
-132
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [1.42.1](https://github.com/aws/aws-cdk/compare/v1.42.0...v1.42.1) (2020-06-01)
6+
7+
8+
### Bug Fixes
9+
10+
* **lambda:** `SingletonFunction.grantInvoke()` API fails with error 'No child with id' ([#8296](https://github.com/aws/aws-cdk/issues/8296)) ([b4e264c](https://github.com/aws/aws-cdk/commit/b4e264c024bc58053412be1343bed6458628f7cb)), closes [#8240](https://github.com/aws/aws-cdk/issues/8240)
11+
512
## [1.42.0](https://github.com/aws/aws-cdk/compare/v1.41.0...v1.42.0) (2020-05-27)
613

714

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"tools/*"
1111
],
1212
"rejectCycles": "true",
13-
"version": "1.42.0"
13+
"version": "1.42.1"
1414
}

packages/@aws-cdk/aws-codepipeline-actions/lib/codecommit/source-action.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ export class CodeCommitSourceAction extends Action {
8787
private readonly props: CodeCommitSourceActionProps;
8888

8989
constructor(props: CodeCommitSourceActionProps) {
90-
const branch = props.branch || 'master';
90+
const branch = props.branch ?? 'master';
91+
if (!branch) {
92+
throw new Error("'branch' parameter cannot be an empty string");
93+
}
9194

9295
super({
9396
...props,
@@ -119,7 +122,8 @@ export class CodeCommitSourceAction extends Action {
119122
const createEvent = this.props.trigger === undefined ||
120123
this.props.trigger === CodeCommitTrigger.EVENTS;
121124
if (createEvent) {
122-
this.props.repository.onCommit(stage.pipeline.node.uniqueId + 'EventRule', {
125+
const branchIdDisambiguator = this.branch === 'master' ? '' : `-${this.branch}-`;
126+
this.props.repository.onCommit(`${stage.pipeline.node.uniqueId}${branchIdDisambiguator}EventRule`, {
123127
target: new targets.CodePipeline(stage.pipeline),
124128
branches: [this.branch],
125129
});

packages/@aws-cdk/aws-codepipeline-actions/test/codecommit/test.codecommit-source-action.ts

+60
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,66 @@ export = {
110110
test.done();
111111
},
112112

113+
'cannot be created with an empty branch'(test: Test) {
114+
const stack = new Stack();
115+
const repo = new codecommit.Repository(stack, 'MyRepo', {
116+
repositoryName: 'my-repo',
117+
});
118+
119+
test.throws(() => {
120+
new cpactions.CodeCommitSourceAction({
121+
actionName: 'Source2',
122+
repository: repo,
123+
output: new codepipeline.Artifact(),
124+
branch: '',
125+
});
126+
}, /'branch' parameter cannot be an empty string/);
127+
128+
test.done();
129+
},
130+
131+
'allows using the same repository multiple times with different branches when trigger=EVENTS'(test: Test) {
132+
const stack = new Stack();
133+
134+
const repo = new codecommit.Repository(stack, 'MyRepo', {
135+
repositoryName: 'my-repo',
136+
});
137+
const sourceOutput1 = new codepipeline.Artifact();
138+
const sourceOutput2 = new codepipeline.Artifact();
139+
new codepipeline.Pipeline(stack, 'MyPipeline', {
140+
stages: [
141+
{
142+
stageName: 'Source',
143+
actions: [
144+
new cpactions.CodeCommitSourceAction({
145+
actionName: 'Source1',
146+
repository: repo,
147+
output: sourceOutput1,
148+
}),
149+
new cpactions.CodeCommitSourceAction({
150+
actionName: 'Source2',
151+
repository: repo,
152+
output: sourceOutput2,
153+
branch: 'develop',
154+
}),
155+
],
156+
},
157+
{
158+
stageName: 'Build',
159+
actions: [
160+
new cpactions.CodeBuildAction({
161+
actionName: 'Build',
162+
project: new codebuild.PipelineProject(stack, 'MyProject'),
163+
input: sourceOutput1,
164+
}),
165+
],
166+
},
167+
],
168+
});
169+
170+
test.done();
171+
},
172+
113173
'exposes variables for other actions to consume'(test: Test) {
114174
const stack = new Stack();
115175

packages/@aws-cdk/aws-events-targets/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Currently supported are:
2222
* Start a StepFunctions state machine
2323
* Queue a Batch job
2424
* Make an AWS API call
25+
* Put a record to a Kinesis stream
2526

2627
See the README of the `@aws-cdk/aws-events` library for more information on
2728
CloudWatch Events.

packages/@aws-cdk/aws-events-targets/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './lambda';
88
export * from './ecs-task-properties';
99
export * from './ecs-task';
1010
export * from './state-machine';
11+
export * from './kinesis-stream';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import * as events from '@aws-cdk/aws-events';
2+
import * as iam from '@aws-cdk/aws-iam';
3+
import * as kinesis from '@aws-cdk/aws-kinesis';
4+
import { singletonEventRole } from './util';
5+
6+
/**
7+
* Customize the Kinesis Stream Event Target
8+
*/
9+
export interface KinesisStreamProps {
10+
/**
11+
* Partition Key Path for records sent to this stream
12+
*
13+
* @default - eventId as the partition key
14+
*/
15+
readonly partitionKeyPath?: string;
16+
17+
/**
18+
* The message to send to the stream.
19+
*
20+
* Must be a valid JSON text passed to the target stream.
21+
*
22+
* @default - the entire CloudWatch event
23+
*/
24+
readonly message?: events.RuleTargetInput;
25+
26+
}
27+
28+
/**
29+
* Use a Kinesis Stream as a target for AWS CloudWatch event rules.
30+
*
31+
* @example
32+
*
33+
* // put to a Kinesis stream every time code is committed
34+
* // to a CodeCommit repository
35+
* repository.onCommit(new targets.KinesisStream(stream));
36+
*
37+
*/
38+
export class KinesisStream implements events.IRuleTarget {
39+
40+
constructor(private readonly stream: kinesis.IStream, private readonly props: KinesisStreamProps = {}) {
41+
}
42+
43+
/**
44+
* Returns a RuleTarget that can be used to trigger this Kinesis Stream as a
45+
* result from a CloudWatch event.
46+
*/
47+
public bind(_rule: events.IRule, _id?: string): events.RuleTargetConfig {
48+
const policyStatements = [new iam.PolicyStatement({
49+
actions: ['kinesis:PutRecord', 'kinesis:PutRecords'],
50+
resources: [this.stream.streamArn],
51+
})];
52+
53+
return {
54+
id: '',
55+
arn: this.stream.streamArn,
56+
role: singletonEventRole(this.stream, policyStatements),
57+
input: this.props.message,
58+
targetResource: this.stream,
59+
kinesisParameters: this.props.partitionKeyPath ? { partitionKeyPath: this.props.partitionKeyPath } : undefined,
60+
};
61+
}
62+
63+
}

packages/@aws-cdk/aws-events-targets/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"@aws-cdk/aws-sqs": "0.0.0",
8989
"@aws-cdk/aws-stepfunctions": "0.0.0",
9090
"@aws-cdk/aws-batch": "0.0.0",
91+
"@aws-cdk/aws-kinesis": "0.0.0",
9192
"@aws-cdk/core": "0.0.0",
9293
"constructs": "^3.0.2"
9394
},
@@ -106,7 +107,8 @@
106107
"@aws-cdk/aws-stepfunctions": "0.0.0",
107108
"@aws-cdk/aws-batch": "0.0.0",
108109
"@aws-cdk/core": "0.0.0",
109-
"constructs": "^3.0.2"
110+
"constructs": "^3.0.2",
111+
"@aws-cdk/aws-kinesis": "0.0.0"
110112
},
111113
"engines": {
112114
"node": ">= 10.13.0 <13 || >=13.7.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"Resources":{
3+
"MyStream5C050E93":{
4+
"Type":"AWS::Kinesis::Stream",
5+
"Properties":{
6+
"ShardCount":1,
7+
"RetentionPeriodHours":24,
8+
"StreamEncryption":{
9+
"Fn::If":[
10+
"AwsCdkKinesisEncryptedStreamsUnsupportedRegions",
11+
{
12+
"Ref":"AWS::NoValue"
13+
},
14+
{
15+
"EncryptionType":"KMS",
16+
"KeyId":"alias/aws/kinesis"
17+
}
18+
]
19+
}
20+
}
21+
},
22+
"MyStreamEventsRole5B6CC6AF":{
23+
"Type":"AWS::IAM::Role",
24+
"Properties":{
25+
"AssumeRolePolicyDocument":{
26+
"Statement":[
27+
{
28+
"Action":"sts:AssumeRole",
29+
"Effect":"Allow",
30+
"Principal":{
31+
"Service":"events.amazonaws.com"
32+
}
33+
}
34+
],
35+
"Version":"2012-10-17"
36+
}
37+
}
38+
},
39+
"MyStreamEventsRoleDefaultPolicy2089B49E":{
40+
"Type":"AWS::IAM::Policy",
41+
"Properties":{
42+
"PolicyDocument":{
43+
"Statement":[
44+
{
45+
"Action":[
46+
"kinesis:PutRecord",
47+
"kinesis:PutRecords"
48+
],
49+
"Effect":"Allow",
50+
"Resource":{
51+
"Fn::GetAtt":[
52+
"MyStream5C050E93",
53+
"Arn"
54+
]
55+
}
56+
}
57+
],
58+
"Version":"2012-10-17"
59+
},
60+
"PolicyName":"MyStreamEventsRoleDefaultPolicy2089B49E",
61+
"Roles":[
62+
{
63+
"Ref":"MyStreamEventsRole5B6CC6AF"
64+
}
65+
]
66+
}
67+
},
68+
"EveryMinute2BBCEA8F":{
69+
"Type":"AWS::Events::Rule",
70+
"Properties":{
71+
"ScheduleExpression":"rate(1 minute)",
72+
"State":"ENABLED",
73+
"Targets":[
74+
{
75+
"Arn":{
76+
"Fn::GetAtt":[
77+
"MyStream5C050E93",
78+
"Arn"
79+
]
80+
},
81+
"Id":"Target0",
82+
"KinesisParameters":{
83+
"PartitionKeyPath":"$.id"
84+
},
85+
"RoleArn":{
86+
"Fn::GetAtt":[
87+
"MyStreamEventsRole5B6CC6AF",
88+
"Arn"
89+
]
90+
}
91+
}
92+
]
93+
}
94+
}
95+
},
96+
"Conditions":{
97+
"AwsCdkKinesisEncryptedStreamsUnsupportedRegions":{
98+
"Fn::Or":[
99+
{
100+
"Fn::Equals":[
101+
{
102+
"Ref":"AWS::Region"
103+
},
104+
"cn-north-1"
105+
]
106+
},
107+
{
108+
"Fn::Equals":[
109+
{
110+
"Ref":"AWS::Region"
111+
},
112+
"cn-northwest-1"
113+
]
114+
}
115+
]
116+
}
117+
}
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as events from '@aws-cdk/aws-events';
2+
import * as kinesis from '@aws-cdk/aws-kinesis';
3+
import * as cdk from '@aws-cdk/core';
4+
import * as targets from '../../lib';
5+
6+
// ---------------------------------
7+
// Define a rule that triggers a put to a Kinesis stream every 1min.
8+
9+
const app = new cdk.App();
10+
11+
const stack = new cdk.Stack(app, 'aws-cdk-kinesis-event-target');
12+
13+
const stream = new kinesis.Stream(stack, 'MyStream');
14+
const event = new events.Rule(stack, 'EveryMinute', {
15+
schedule: events.Schedule.rate(cdk.Duration.minutes(1)),
16+
});
17+
18+
event.addTarget(new targets.KinesisStream(stream, {
19+
partitionKeyPath: events.EventField.eventId,
20+
}));
21+
22+
app.synth();

0 commit comments

Comments
 (0)