Skip to content

Commit

Permalink
Merge branch 'master' into issue_8277
Browse files Browse the repository at this point in the history
  • Loading branch information
plastic-karma authored Jun 2, 2020
2 parents f2e0c4e + 44f2423 commit 5b78852
Show file tree
Hide file tree
Showing 37 changed files with 732 additions and 132 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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.

## [1.42.1](https://github.com/aws/aws-cdk/compare/v1.42.0...v1.42.1) (2020-06-01)


### Bug Fixes

* **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)

## [1.42.0](https://github.com/aws/aws-cdk/compare/v1.41.0...v1.42.0) (2020-05-27)


Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"tools/*"
],
"rejectCycles": "true",
"version": "1.42.0"
"version": "1.42.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export class CodeCommitSourceAction extends Action {
private readonly props: CodeCommitSourceActionProps;

constructor(props: CodeCommitSourceActionProps) {
const branch = props.branch || 'master';
const branch = props.branch ?? 'master';
if (!branch) {
throw new Error("'branch' parameter cannot be an empty string");
}

super({
...props,
Expand Down Expand Up @@ -119,7 +122,8 @@ export class CodeCommitSourceAction extends Action {
const createEvent = this.props.trigger === undefined ||
this.props.trigger === CodeCommitTrigger.EVENTS;
if (createEvent) {
this.props.repository.onCommit(stage.pipeline.node.uniqueId + 'EventRule', {
const branchIdDisambiguator = this.branch === 'master' ? '' : `-${this.branch}-`;
this.props.repository.onCommit(`${stage.pipeline.node.uniqueId}${branchIdDisambiguator}EventRule`, {
target: new targets.CodePipeline(stage.pipeline),
branches: [this.branch],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,66 @@ export = {
test.done();
},

'cannot be created with an empty branch'(test: Test) {
const stack = new Stack();
const repo = new codecommit.Repository(stack, 'MyRepo', {
repositoryName: 'my-repo',
});

test.throws(() => {
new cpactions.CodeCommitSourceAction({
actionName: 'Source2',
repository: repo,
output: new codepipeline.Artifact(),
branch: '',
});
}, /'branch' parameter cannot be an empty string/);

test.done();
},

'allows using the same repository multiple times with different branches when trigger=EVENTS'(test: Test) {
const stack = new Stack();

const repo = new codecommit.Repository(stack, 'MyRepo', {
repositoryName: 'my-repo',
});
const sourceOutput1 = new codepipeline.Artifact();
const sourceOutput2 = new codepipeline.Artifact();
new codepipeline.Pipeline(stack, 'MyPipeline', {
stages: [
{
stageName: 'Source',
actions: [
new cpactions.CodeCommitSourceAction({
actionName: 'Source1',
repository: repo,
output: sourceOutput1,
}),
new cpactions.CodeCommitSourceAction({
actionName: 'Source2',
repository: repo,
output: sourceOutput2,
branch: 'develop',
}),
],
},
{
stageName: 'Build',
actions: [
new cpactions.CodeBuildAction({
actionName: 'Build',
project: new codebuild.PipelineProject(stack, 'MyProject'),
input: sourceOutput1,
}),
],
},
],
});

test.done();
},

'exposes variables for other actions to consume'(test: Test) {
const stack = new Stack();

Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-events-targets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Currently supported are:
* Start a StepFunctions state machine
* Queue a Batch job
* Make an AWS API call
* Put a record to a Kinesis stream

See the README of the `@aws-cdk/aws-events` library for more information on
CloudWatch Events.
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-events-targets/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './lambda';
export * from './ecs-task-properties';
export * from './ecs-task';
export * from './state-machine';
export * from './kinesis-stream';
63 changes: 63 additions & 0 deletions packages/@aws-cdk/aws-events-targets/lib/kinesis-stream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as events from '@aws-cdk/aws-events';
import * as iam from '@aws-cdk/aws-iam';
import * as kinesis from '@aws-cdk/aws-kinesis';
import { singletonEventRole } from './util';

/**
* Customize the Kinesis Stream Event Target
*/
export interface KinesisStreamProps {
/**
* Partition Key Path for records sent to this stream
*
* @default - eventId as the partition key
*/
readonly partitionKeyPath?: string;

/**
* The message to send to the stream.
*
* Must be a valid JSON text passed to the target stream.
*
* @default - the entire CloudWatch event
*/
readonly message?: events.RuleTargetInput;

}

/**
* Use a Kinesis Stream as a target for AWS CloudWatch event rules.
*
* @example
*
* // put to a Kinesis stream every time code is committed
* // to a CodeCommit repository
* repository.onCommit(new targets.KinesisStream(stream));
*
*/
export class KinesisStream implements events.IRuleTarget {

constructor(private readonly stream: kinesis.IStream, private readonly props: KinesisStreamProps = {}) {
}

/**
* Returns a RuleTarget that can be used to trigger this Kinesis Stream as a
* result from a CloudWatch event.
*/
public bind(_rule: events.IRule, _id?: string): events.RuleTargetConfig {
const policyStatements = [new iam.PolicyStatement({
actions: ['kinesis:PutRecord', 'kinesis:PutRecords'],
resources: [this.stream.streamArn],
})];

return {
id: '',
arn: this.stream.streamArn,
role: singletonEventRole(this.stream, policyStatements),
input: this.props.message,
targetResource: this.stream,
kinesisParameters: this.props.partitionKeyPath ? { partitionKeyPath: this.props.partitionKeyPath } : undefined,
};
}

}
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-events-targets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@aws-cdk/aws-sqs": "0.0.0",
"@aws-cdk/aws-stepfunctions": "0.0.0",
"@aws-cdk/aws-batch": "0.0.0",
"@aws-cdk/aws-kinesis": "0.0.0",
"@aws-cdk/core": "0.0.0",
"constructs": "^3.0.2"
},
Expand All @@ -106,7 +107,8 @@
"@aws-cdk/aws-stepfunctions": "0.0.0",
"@aws-cdk/aws-batch": "0.0.0",
"@aws-cdk/core": "0.0.0",
"constructs": "^3.0.2"
"constructs": "^3.0.2",
"@aws-cdk/aws-kinesis": "0.0.0"
},
"engines": {
"node": ">= 10.13.0 <13 || >=13.7.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"Resources":{
"MyStream5C050E93":{
"Type":"AWS::Kinesis::Stream",
"Properties":{
"ShardCount":1,
"RetentionPeriodHours":24,
"StreamEncryption":{
"Fn::If":[
"AwsCdkKinesisEncryptedStreamsUnsupportedRegions",
{
"Ref":"AWS::NoValue"
},
{
"EncryptionType":"KMS",
"KeyId":"alias/aws/kinesis"
}
]
}
}
},
"MyStreamEventsRole5B6CC6AF":{
"Type":"AWS::IAM::Role",
"Properties":{
"AssumeRolePolicyDocument":{
"Statement":[
{
"Action":"sts:AssumeRole",
"Effect":"Allow",
"Principal":{
"Service":"events.amazonaws.com"
}
}
],
"Version":"2012-10-17"
}
}
},
"MyStreamEventsRoleDefaultPolicy2089B49E":{
"Type":"AWS::IAM::Policy",
"Properties":{
"PolicyDocument":{
"Statement":[
{
"Action":[
"kinesis:PutRecord",
"kinesis:PutRecords"
],
"Effect":"Allow",
"Resource":{
"Fn::GetAtt":[
"MyStream5C050E93",
"Arn"
]
}
}
],
"Version":"2012-10-17"
},
"PolicyName":"MyStreamEventsRoleDefaultPolicy2089B49E",
"Roles":[
{
"Ref":"MyStreamEventsRole5B6CC6AF"
}
]
}
},
"EveryMinute2BBCEA8F":{
"Type":"AWS::Events::Rule",
"Properties":{
"ScheduleExpression":"rate(1 minute)",
"State":"ENABLED",
"Targets":[
{
"Arn":{
"Fn::GetAtt":[
"MyStream5C050E93",
"Arn"
]
},
"Id":"Target0",
"KinesisParameters":{
"PartitionKeyPath":"$.id"
},
"RoleArn":{
"Fn::GetAtt":[
"MyStreamEventsRole5B6CC6AF",
"Arn"
]
}
}
]
}
}
},
"Conditions":{
"AwsCdkKinesisEncryptedStreamsUnsupportedRegions":{
"Fn::Or":[
{
"Fn::Equals":[
{
"Ref":"AWS::Region"
},
"cn-north-1"
]
},
{
"Fn::Equals":[
{
"Ref":"AWS::Region"
},
"cn-northwest-1"
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as events from '@aws-cdk/aws-events';
import * as kinesis from '@aws-cdk/aws-kinesis';
import * as cdk from '@aws-cdk/core';
import * as targets from '../../lib';

// ---------------------------------
// Define a rule that triggers a put to a Kinesis stream every 1min.

const app = new cdk.App();

const stack = new cdk.Stack(app, 'aws-cdk-kinesis-event-target');

const stream = new kinesis.Stream(stack, 'MyStream');
const event = new events.Rule(stack, 'EveryMinute', {
schedule: events.Schedule.rate(cdk.Duration.minutes(1)),
});

event.addTarget(new targets.KinesisStream(stream, {
partitionKeyPath: events.EventField.eventId,
}));

app.synth();
Loading

0 comments on commit 5b78852

Please sign in to comment.