Skip to content

Commit

Permalink
fix(sns) UrlSubscription: don't validate protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
spg committed Jun 19, 2019
1 parent ea10f0d commit 651d5a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions packages/@aws-cdk/aws-sns-subscriptions/lib/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ export interface UrlSubscriptionProps {
* @see https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html
*/
export class UrlSubscription implements sns.ITopicSubscription {
constructor(private readonly url: string, private readonly props: UrlSubscriptionProps = {}) {
if (!url.startsWith('http://') && !url.startsWith('https://')) {
throw new Error('URL must start with either http:// or https://');
}
constructor(private readonly url: string, private readonly protocol: sns.SubscriptionProtocol, private readonly props: UrlSubscriptionProps = {}) {
}

public bind(scope: Construct, topic: sns.ITopic): void {
new sns.Subscription(scope, this.url, {
topic,
endpoint: this.url,
protocol: this.url.startsWith('https:') ? sns.SubscriptionProtocol.Https : sns.SubscriptionProtocol.Http,
protocol: this.protocol,
rawMessageDelivery: this.props.rawMessageDelivery,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-sns-subscriptions/test/subs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ beforeEach(() => {
});

test('url subscription', () => {
topic.addSubscription(new subs.UrlSubscription('https://foobar.com/'));
topic.addSubscription(new subs.UrlSubscription('https://foobar.com/', sns.SubscriptionProtocol.Https));

expect(stack).toMatchTemplate({
"Resources": {
Expand All @@ -45,7 +45,7 @@ test('url subscription', () => {
});

test('url subscription (with raw delivery)', () => {
topic.addSubscription(new subs.UrlSubscription('https://foobar.com/', {
topic.addSubscription(new subs.UrlSubscription('https://foobar.com/', sns.SubscriptionProtocol.Https, {
rawMessageDelivery: true
}));

Expand Down

0 comments on commit 651d5a0

Please sign in to comment.