Skip to content

Commit

Permalink
Check if url is unresolved
Browse files Browse the repository at this point in the history
  • Loading branch information
spg committed Jun 20, 2019
1 parent ea10f0d commit fb7d856
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-sns-subscriptions/lib/url.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sns = require('@aws-cdk/aws-sns');
import { Construct } from '@aws-cdk/cdk';
import { Construct, Token } from '@aws-cdk/cdk';

/**
* Options for URL subscriptions.
Expand All @@ -23,17 +23,17 @@ 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://')) {
constructor(private readonly url: string, private readonly protocol: sns.SubscriptionProtocol, private readonly props: UrlSubscriptionProps = {}) {
if (!Token.isUnresolved(url) && !url.startsWith('http://') && !url.startsWith('https://')) {
throw new Error('URL must start with either http:// or https://');
}
}

public bind(scope: Construct, topic: sns.ITopic): void {
new sns.Subscription(scope, this.url, {
new sns.Subscription(scope, topic.node.uniqueId + '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 fb7d856

Please sign in to comment.