-
Notifications
You must be signed in to change notification settings - Fork 4k
/
subscription.ts
103 lines (87 loc) · 2.31 KB
/
subscription.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Construct } from '@aws-cdk/cdk';
import { CfnSubscription } from './sns.generated';
import { ITopic } from './topic-base';
/**
* Properties for creating a new subscription
*/
export interface SubscriptionProps {
/**
* What type of subscription to add.
*/
readonly protocol: SubscriptionProtocol;
/**
* The subscription endpoint.
*
* The meaning of this value depends on the value for 'protocol'.
*/
readonly endpoint: any;
/**
* The topic to subscribe to.
*/
readonly topic: ITopic;
/**
* true if raw message delivery is enabled for the subscription. Raw messages are free of JSON formatting and can be
* sent to HTTP/S and Amazon SQS endpoints. For more information, see GetSubscriptionAttributes in the Amazon Simple
* Notification Service API Reference.
*
* @default false
*/
readonly rawMessageDelivery?: boolean;
}
/**
* A new subscription.
*
* Prefer to use the `ITopic.subscribeXxx()` methods to creating instances of
* this class.
*/
export class Subscription extends Construct {
constructor(scope: Construct, id: string, props: SubscriptionProps) {
super(scope, id);
if (props.rawMessageDelivery && ['http', 'https', 'sqs'].indexOf(props.protocol) < 0) {
throw new Error('Raw message delivery can only be enabled for HTTP/S and SQS subscriptions.');
}
new CfnSubscription(this, 'Resource', {
endpoint: props.endpoint,
protocol: props.protocol,
topicArn: props.topic.topicArn,
rawMessageDelivery: props.rawMessageDelivery,
});
}
}
/**
* The type of subscription, controlling the type of the endpoint parameter.
*/
export enum SubscriptionProtocol {
/**
* JSON-encoded message is POSTED to an HTTP url.
*/
Http = 'http',
/**
* JSON-encoded message is POSTed to an HTTPS url.
*/
Https = 'https',
/**
* Notifications are sent via email.
*/
Email = 'email',
/**
* Notifications are JSON-encoded and sent via mail.
*/
EmailJson = 'email-json',
/**
* Notification is delivered by SMS
*/
Sms = 'sms',
/**
* Notifications are enqueued into an SQS queue.
*/
Sqs = 'sqs',
/**
* JSON-encoded notifications are sent to a mobile app endpoint.
*/
Application = 'application',
/**
* Notifications trigger a Lambda function.
*/
Lambda = 'lambda'
}