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 21, 2019
1 parent 9101161 commit 1b2f72e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 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 { SubscriptionProps } from './subscription';
import { Construct, Token } from '@aws-cdk/cdk';

/**
* Options for URL subscriptions.
Expand All @@ -23,17 +23,17 @@ export interface UrlSubscriptionProps extends SubscriptionProps {
* @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(_topic: sns.ITopic): sns.TopicSubscriptionConfig {
return {
subscriberId: this.url,
public bind(scope: Construct, topic: sns.ITopic): void {
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,
filterPolicy: this.props.filterPolicy,
};
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 1b2f72e

Please sign in to comment.