Skip to content

Commit

Permalink
Revert "fix: update all 'onXxx' methods to be CloudWatch Events (#2609)"
Browse files Browse the repository at this point in the history
This reverts commit 28942d2.
  • Loading branch information
rix0rrr committed May 23, 2019
1 parent 9b4db42 commit 073b6b3
Show file tree
Hide file tree
Showing 54 changed files with 285 additions and 1,090 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class StepScalingPolicy extends cdk.Construct {
evaluationPeriods: 1,
threshold,
});
this.lowerAlarm.addAlarmAction(this.lowerAction);
this.lowerAlarm.onAlarm(this.lowerAction);
}

if (alarms.upperAlarmIntervalIndex !== undefined) {
Expand Down Expand Up @@ -138,7 +138,7 @@ export class StepScalingPolicy extends cdk.Construct {
evaluationPeriods: 1,
threshold,
});
this.upperAlarm.addAlarmAction(this.upperAction);
this.upperAlarm.onAlarm(this.upperAction);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ abstract class AutoScalingGroupBase extends Resource implements IAutoScalingGrou
/**
* Send a message to either an SQS queue or SNS topic when instances launch or terminate
*/
public addLifecycleHook(id: string, props: BasicLifecycleHookProps): LifecycleHook {
public onLifecycleTransition(id: string, props: BasicLifecycleHookProps): LifecycleHook {
return new LifecycleHook(this, `LifecycleHook${id}`, {
autoScalingGroup: this,
...props
Expand Down Expand Up @@ -701,7 +701,7 @@ export interface IAutoScalingGroup extends IResource {
/**
* Send a message to either an SQS queue or SNS topic when instances launch or terminate
*/
addLifecycleHook(id: string, props: BasicLifecycleHookProps): LifecycleHook;
onLifecycleTransition(id: string, props: BasicLifecycleHookProps): LifecycleHook;

/**
* Scale out or in based on time
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/lib/step-scaling-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class StepScalingPolicy extends cdk.Construct {
evaluationPeriods: 1,
threshold,
});
this.lowerAlarm.addAlarmAction(this.lowerAction);
this.lowerAlarm.onAlarm(this.lowerAction);
}

if (alarms.upperAlarmIntervalIndex !== undefined) {
Expand Down Expand Up @@ -139,7 +139,7 @@ export class StepScalingPolicy extends cdk.Construct {
evaluationPeriods: 1,
threshold,
});
this.upperAlarm.addAlarmAction(this.upperAction);
this.upperAlarm.onAlarm(this.upperAction);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export = {
});

// WHEN
asg.addLifecycleHook('Transition', {
asg.onLifecycleTransition('Transition', {
notificationTarget: new FakeNotificationTarget(),
lifecycleTransition: autoscaling.LifecycleTransition.InstanceLaunching,
defaultResult: autoscaling.DefaultResult.Abandon,
Expand Down
68 changes: 0 additions & 68 deletions packages/@aws-cdk/aws-cloudtrail/SAMPLE-EVENTS.md

This file was deleted.

14 changes: 6 additions & 8 deletions packages/@aws-cdk/aws-cloudtrail/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,14 @@ export class Trail extends Resource {
}

/**
* Create an event rule for when an event is recorded by any Trail in the account.
* Create an event rule for when an event is recorded by any trail.
*
* Note that the event doesn't necessarily have to come from this Trail, it can
* be captured from any one.
*
* Be sure to filter the event further down using an event pattern.
* Note that the event doesn't necessarily have to come from this
* trail. Be sure to filter the event properly using an event pattern.
*/
public onCloudTrailEvent(id: string, options: events.OnEventOptions): events.Rule {
const rule = new events.Rule(this, id, options);
rule.addTarget(options.target);
public onEvent(name: string, target?: events.IRuleTarget, options?: events.RuleProps) {
const rule = new events.Rule(this, name, options);
rule.addTarget(target);
rule.addEventPattern({
detailType: ['AWS API Call via CloudTrail']
});
Expand Down
12 changes: 5 additions & 7 deletions packages/@aws-cdk/aws-cloudtrail/test/test.cloudtrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,11 @@ export = {
const trail = new Trail(stack, 'MyAmazingCloudTrail', { managementEvents: ReadWriteType.WriteOnly });

// WHEN
trail.onCloudTrailEvent('DoEvents', {
target: {
bind: () => ({
arn: 'arn',
id: 'myid'
})
}
trail.onEvent('DoEvents', {
bind: () => ({
arn: 'arn',
id: 'myid'
})
});

// THEN
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class Alarm extends Resource implements IAlarm {
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public addAlarmAction(...actions: IAlarmAction[]) {
public onAlarm(...actions: IAlarmAction[]) {
if (this.alarmActionArns === undefined) {
this.alarmActionArns = [];
}
Expand All @@ -168,7 +168,7 @@ export class Alarm extends Resource implements IAlarm {
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public addInsufficientDataAction(...actions: IAlarmAction[]) {
public onInsufficientData(...actions: IAlarmAction[]) {
if (this.insufficientDataActionArns === undefined) {
this.insufficientDataActionArns = [];
}
Expand All @@ -181,7 +181,7 @@ export class Alarm extends Resource implements IAlarm {
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public addOkAction(...actions: IAlarmAction[]) {
public onOk(...actions: IAlarmAction[]) {
if (this.okActionArns === undefined) {
this.okActionArns = [];
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-cloudwatch/test/test.alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export = {
evaluationPeriods: 2
});

alarm.addAlarmAction(new TestAlarmAction('A'));
alarm.addInsufficientDataAction(new TestAlarmAction('B'));
alarm.addOkAction(new TestAlarmAction('C'));
alarm.onAlarm(new TestAlarmAction('A'));
alarm.onInsufficientData(new TestAlarmAction('B'));
alarm.onOk(new TestAlarmAction('C'));

// THEN
expect(stack).to(haveResource('AWS::CloudWatch::Alarm', {
Expand Down
68 changes: 29 additions & 39 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ export interface IProject extends IResource, iam.IGrantable {
/** The IAM service Role of this Project. Undefined for imported Projects. */
readonly role?: iam.IRole;

/**
* Defines a CloudWatch event rule triggered when something happens with this project.
*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
*/
onEvent(id: string, options: events.OnEventOptions): events.Rule;

/**
* Defines a CloudWatch event rule triggered when the build project state
* changes. You can filter specific build status events using an event
Expand All @@ -64,30 +57,30 @@ export interface IProject extends IResource, iam.IGrantable {
*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
*/
onStateChange(id: string, options: events.OnEventOptions): events.Rule;
onStateChange(name: string, target?: events.IRuleTarget, options?: events.RuleProps): events.Rule;

/**
* Defines a CloudWatch event rule that triggers upon phase change of this
* build project.
*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
*/
onPhaseChange(id: string, options: events.OnEventOptions): events.Rule;
onPhaseChange(name: string, target?: events.IRuleTarget, options?: events.RuleProps): events.Rule;

/**
* Defines an event rule which triggers when a build starts.
*/
onBuildStarted(id: string, options: events.OnEventOptions): events.Rule;
onBuildStarted(name: string, target?: events.IRuleTarget, options?: events.RuleProps): events.Rule;

/**
* Defines an event rule which triggers when a build fails.
*/
onBuildFailed(id: string, options: events.OnEventOptions): events.Rule;
onBuildFailed(name: string, target?: events.IRuleTarget, options?: events.RuleProps): events.Rule;

/**
* Defines an event rule which triggers when a build completes successfully.
*/
onBuildSucceeded(id: string, options: events.OnEventOptions): events.Rule;
onBuildSucceeded(name: string, target?: events.IRuleTarget, options?: events.RuleProps): events.Rule;

/**
* @returns a CloudWatch metric associated with this build project.
Expand Down Expand Up @@ -164,23 +157,6 @@ abstract class ProjectBase extends Resource implements IProject {
/** The IAM service Role of this Project. */
public abstract readonly role?: iam.IRole;

/**
* Defines a CloudWatch event rule triggered when something happens with this project.
*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
*/
public onEvent(id: string, options: events.OnEventOptions): events.Rule {
const rule = new events.Rule(this, id, options);
rule.addTarget(options.target);
rule.addEventPattern({
source: ['aws.codebuild'],
detail: {
'project-name': [this.projectName]
}
});
return rule;
}

/**
* Defines a CloudWatch event rule triggered when the build project state
* changes. You can filter specific build status events using an event
Expand All @@ -206,10 +182,17 @@ abstract class ProjectBase extends Resource implements IProject {
*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
*/
public onStateChange(id: string, options: events.OnEventOptions) {
const rule = this.onEvent(id, options);
public onStateChange(name: string, target?: events.IRuleTarget, options?: events.RuleProps) {
const rule = new events.Rule(this, name, options);
rule.addTarget(target);
rule.addEventPattern({
source: ['aws.codebuild'],
detailType: ['CodeBuild Build State Change'],
detail: {
'project-name': [
this.projectName
]
}
});
return rule;
}
Expand All @@ -220,10 +203,17 @@ abstract class ProjectBase extends Resource implements IProject {
*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
*/
public onPhaseChange(id: string, options: events.OnEventOptions) {
const rule = this.onEvent(id, options);
public onPhaseChange(name: string, target?: events.IRuleTarget, options?: events.RuleProps) {
const rule = new events.Rule(this, name, options);
rule.addTarget(target);
rule.addEventPattern({
source: ['aws.codebuild'],
detailType: ['CodeBuild Build Phase Change'],
detail: {
'project-name': [
this.projectName
]
}
});
return rule;
}
Expand All @@ -234,8 +224,8 @@ abstract class ProjectBase extends Resource implements IProject {
* To access fields from the event in the event target input,
* use the static fields on the `StateChangeEvent` class.
*/
public onBuildStarted(id: string, options: events.OnEventOptions) {
const rule = this.onStateChange(id, options);
public onBuildStarted(name: string, target?: events.IRuleTarget, options?: events.RuleProps) {
const rule = this.onStateChange(name, target, options);
rule.addEventPattern({
detail: {
'build-status': ['IN_PROGRESS']
Expand All @@ -250,8 +240,8 @@ abstract class ProjectBase extends Resource implements IProject {
* To access fields from the event in the event target input,
* use the static fields on the `StateChangeEvent` class.
*/
public onBuildFailed(id: string, options: events.OnEventOptions) {
const rule = this.onStateChange(id, options);
public onBuildFailed(name: string, target?: events.IRuleTarget, options?: events.RuleProps) {
const rule = this.onStateChange(name, target, options);
rule.addEventPattern({
detail: {
'build-status': ['FAILED']
Expand All @@ -266,8 +256,8 @@ abstract class ProjectBase extends Resource implements IProject {
* To access fields from the event in the event target input,
* use the static fields on the `StateChangeEvent` class.
*/
public onBuildSucceeded(id: string, options: events.OnEventOptions) {
const rule = this.onStateChange(id, options);
public onBuildSucceeded(name: string, target?: events.IRuleTarget, options?: events.RuleProps) {
const rule = this.onStateChange(name, target, options);
rule.addEventPattern({
detail: {
'build-status': ['SUCCEEDED']
Expand Down
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,11 @@ export = {
source: new codebuild.CodePipelineSource()
});

project.onBuildFailed('OnBuildFailed', { target: { bind: () => ({ arn: 'ARN', id: 'ID' }) }});
project.onBuildSucceeded('OnBuildSucceeded', { target: { bind: () => ({ arn: 'ARN', id: 'ID' }) }});
project.onPhaseChange('OnPhaseChange', { target: { bind: () => ({ arn: 'ARN', id: 'ID' }) }});
project.onStateChange('OnStateChange', { target: { bind: () => ({ arn: 'ARN', id: 'ID' }) }});
project.onBuildStarted('OnBuildStarted', { target: { bind: () => ({ arn: 'ARN', id: 'ID' }) }});
project.onBuildFailed('OnBuildFailed');
project.onBuildSucceeded('OnBuildSucceeded');
project.onPhaseChange('OnPhaseChange');
project.onStateChange('OnStateChange');
project.onBuildStarted('OnBuildStarted');

expect(stack).to(haveResource('AWS::Events::Rule', {
"EventPattern": {
Expand Down
Loading

0 comments on commit 073b6b3

Please sign in to comment.