Skip to content

Commit

Permalink
refactor(sns): move subscribers to aws-sns-subscribers (#2804)
Browse files Browse the repository at this point in the history
In accordance with new guidelines, we're centralizing cross-service
integrations into their own package. In this case, centralizing
SNS Subscribers into @aws-cdk/aws-sns-subscribers.

BREAKING CHANGE: using a queue, lambda, email, URL as SNS Subscriber now
requires an integration object from the `@aws-cdk/aws-sns-subscribers`
package.
  • Loading branch information
rix0rrr authored Jun 11, 2019
1 parent a12fcfa commit 9ef899c
Show file tree
Hide file tree
Showing 69 changed files with 6,042 additions and 727 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/app-delivery/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/assert/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/assets-docker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-autoscaling-common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import autoscaling = require('@aws-cdk/aws-autoscaling');
import lambda = require('@aws-cdk/aws-lambda');
import sns = require('@aws-cdk/aws-sns');
import subs = require('@aws-cdk/aws-sns-subscriptions');
import { Construct } from '@aws-cdk/cdk';
import { TopicHook } from './topic-hook';

Expand All @@ -15,7 +16,7 @@ export class FunctionHook implements autoscaling.ILifecycleHookTarget {

public bind(scope: Construct, lifecycleHook: autoscaling.ILifecycleHook): autoscaling.LifecycleHookTargetConfig {
const topic = new sns.Topic(scope, 'Topic');
topic.subscribeLambda(this.fn);
topic.addSubscription(new subs.LambdaSubscription(this.fn));
return new TopicHook(topic).bind(scope, lifecycleHook);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-autoscaling-hooktargets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@aws-cdk/aws-iam": "^0.34.0",
"@aws-cdk/aws-lambda": "^0.34.0",
"@aws-cdk/aws-sns": "^0.34.0",
"@aws-cdk/aws-sns-subscriptions": "^0.34.0",
"@aws-cdk/aws-sqs": "^0.34.0",
"@aws-cdk/cdk": "^0.34.0"
},
Expand All @@ -90,11 +91,12 @@
"@aws-cdk/aws-iam": "^0.34.0",
"@aws-cdk/aws-lambda": "^0.34.0",
"@aws-cdk/aws-sns": "^0.34.0",
"@aws-cdk/aws-sns-subscriptions": "^0.34.0",
"@aws-cdk/aws-sqs": "^0.34.0",
"@aws-cdk/cdk": "^0.34.0"
},
"engines": {
"node": ">= 8.10.0"
},
"stability": "experimental"
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudtrail/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudwatch-actions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codecommit/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import codepipeline = require('@aws-cdk/aws-codepipeline');
import sns = require('@aws-cdk/aws-sns');
import subs = require('@aws-cdk/aws-sns-subscriptions');
import cdk = require('@aws-cdk/cdk');

/**
Expand Down Expand Up @@ -62,7 +63,7 @@ export class ManualApprovalAction extends codepipeline.Action {
if (this._notificationTopic) {
this._notificationTopic.grantPublish(info.role);
for (const notifyEmail of this.props.notifyEmails || []) {
this._notificationTopic.subscribeEmail(`Subscription-${notifyEmail}`, notifyEmail);
this._notificationTopic.addSubscription(new subs.EmailSubscription(notifyEmail));
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-codepipeline-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@aws-cdk/aws-lambda": "^0.34.0",
"@aws-cdk/aws-s3": "^0.34.0",
"@aws-cdk/aws-sns": "^0.34.0",
"@aws-cdk/aws-sns-subscriptions": "^0.34.0",
"@aws-cdk/cdk": "^0.34.0"
},
"homepage": "https://github.com/awslabs/aws-cdk",
Expand All @@ -103,10 +104,11 @@
"@aws-cdk/aws-lambda": "^0.34.0",
"@aws-cdk/aws-s3": "^0.34.0",
"@aws-cdk/aws-sns": "^0.34.0",
"@aws-cdk/aws-sns-subscriptions": "^0.34.0",
"@aws-cdk/cdk": "^0.34.0"
},
"engines": {
"node": ">= 8.10.0"
},
"stability": "experimental"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"PipelineApproveManualApprovalTopicResourceF5A35B20": {
"Type": "AWS::SNS::Topic"
},
"PipelineApproveManualApprovalTopicResourceSubscriptionadamruka85gmailcom76398FFA": {
"PipelineApproveManualApprovalTopicResourceadamruka85gmailcom202874CD": {
"Type": "AWS::SNS::Subscription",
"Properties": {
"Protocol": "email",
Expand All @@ -203,4 +203,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs-patterns/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-events-targets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-events-targets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@aws-cdk/aws-iam": "^0.34.0",
"@aws-cdk/aws-lambda": "^0.34.0",
"@aws-cdk/aws-sns": "^0.34.0",
"@aws-cdk/aws-sns-subscriptions": "^0.34.0",
"@aws-cdk/aws-stepfunctions": "^0.34.0",
"@aws-cdk/cdk": "^0.34.0"
},
Expand All @@ -103,6 +104,7 @@
"@aws-cdk/aws-iam": "^0.34.0",
"@aws-cdk/aws-lambda": "^0.34.0",
"@aws-cdk/aws-sns": "^0.34.0",
"@aws-cdk/aws-sns-subscriptions": "^0.34.0",
"@aws-cdk/aws-sqs": "^0.34.0",
"@aws-cdk/aws-stepfunctions": "^0.34.0",
"@aws-cdk/cdk": "^0.34.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import codebuild = require('@aws-cdk/aws-codebuild');
import codecommit = require('@aws-cdk/aws-codecommit');
import events = require('@aws-cdk/aws-events');
import sns = require('@aws-cdk/aws-sns');
import subs = require('@aws-cdk/aws-sns-subscriptions');
import sqs = require('@aws-cdk/aws-sqs');
import cdk = require('@aws-cdk/cdk');
import targets = require('../../lib');
Expand All @@ -19,7 +20,7 @@ const project = new codebuild.Project(stack, 'MyProject', {
const queue = new sqs.Queue(stack, 'MyQueue');

const topic = new sns.Topic(stack, 'MyTopic');
topic.subscribeQueue(queue);
topic.addSubscription(new subs.SqsSubscription(queue));

// this will send an email with the JSON event for every state change of this
// build project.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import events = require('@aws-cdk/aws-events');
import sns = require('@aws-cdk/aws-sns');
import subs = require('@aws-cdk/aws-sns-subscriptions');
import sqs = require('@aws-cdk/aws-sqs');
import cdk = require('@aws-cdk/cdk');
import targets = require('../../lib');
Expand All @@ -19,7 +20,7 @@ const event = new events.Rule(stack, 'EveryMinute', {
});

const queue = new sqs.Queue(stack, 'MyQueue');
topic.subscribeQueue(queue);
topic.addSubscription(new subs.SqsSubscription(queue));

event.addTarget(new targets.SnsTopic(topic));

Expand Down
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-lambda-event-sources/lib/sns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import lambda = require('@aws-cdk/aws-lambda');
import sns = require('@aws-cdk/aws-sns');
import subs = require('@aws-cdk/aws-sns-subscriptions');

/**
* Use an Amazon SNS topic as an event source for AWS Lambda.
Expand All @@ -9,6 +10,6 @@ export class SnsEventSource implements lambda.IEventSource {
}

public bind(target: lambda.IFunction) {
this.topic.subscribeLambda(target);
this.topic.addSubscription(new subs.LambdaSubscription(target));
}
}
}
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-lambda-event-sources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@aws-cdk/aws-s3": "^0.34.0",
"@aws-cdk/aws-s3-notifications": "^0.34.0",
"@aws-cdk/aws-sns": "^0.34.0",
"@aws-cdk/aws-sns-subscriptions": "^0.34.0",
"@aws-cdk/aws-sqs": "^0.34.0",
"@aws-cdk/cdk": "^0.34.0"
},
Expand All @@ -85,11 +86,12 @@
"@aws-cdk/aws-s3": "^0.34.0",
"@aws-cdk/aws-s3-notifications": "^0.34.0",
"@aws-cdk/aws-sns": "^0.34.0",
"@aws-cdk/aws-sns-subscriptions": "^0.34.0",
"@aws-cdk/aws-sqs": "^0.34.0",
"@aws-cdk/cdk": "^0.34.0"
},
"engines": {
"node": ">= 8.10.0"
},
"stability": "experimental"
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-logs-destinations/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-route53-targets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-route53/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-s3-notifications/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-sns-subscriptions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.js
tsconfig.json
tslint.json
*.js.map
*.d.ts
*.generated.ts
dist
lib/generated/resources.ts
.jsii

.LAST_BUILD
.nyc_output
coverage
.nycrc
.LAST_PACKAGE
*.snk
18 changes: 18 additions & 0 deletions packages/@aws-cdk/aws-sns-subscriptions/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz

dist
.LAST_PACKAGE
.LAST_BUILD
!*.js

# Include .jsii
!.jsii

*.snk

*.tsbuildinfo
Loading

0 comments on commit 9ef899c

Please sign in to comment.