-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
configuration-set.ts
182 lines (161 loc) · 4.83 KB
/
configuration-set.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { Construct } from 'constructs';
import { ConfigurationSetEventDestination, ConfigurationSetEventDestinationOptions } from './configuration-set-event-destination';
import { IDedicatedIpPool } from './dedicated-ip-pool';
import { undefinedIfNoKeys } from './private/utils';
import { CfnConfigurationSet } from './ses.generated';
import { IResource, Resource } from '../../core';
/**
* A configuration set
*/
export interface IConfigurationSet extends IResource {
/**
* The name of the configuration set
*
* @attribute
*/
readonly configurationSetName: string;
}
/**
* Properties for a configuration set
*/
export interface ConfigurationSetProps {
/**
* A name for the configuration set
*
* @default - a CloudFormation generated name
*/
readonly configurationSetName?: string;
/**
* The dedicated IP pool to associate with the configuration set
*
* @default - do not use a dedicated IP pool
*/
readonly dedicatedIpPool?: IDedicatedIpPool;
/**
* Specifies whether messages that use the configuration set are required to
* use Transport Layer Security (TLS)
*
* @default ConfigurationSetTlsPolicy.OPTIONAL
*/
readonly tlsPolicy?: ConfigurationSetTlsPolicy;
/**
* Whether to publish reputation metrics for the configuration set, such as
* bounce and complaint rates, to Amazon CloudWatch
*
* @default false
*/
readonly reputationMetrics?: boolean;
/**
* Whether email sending is enabled
*
* @default true
*/
readonly sendingEnabled?: boolean;
/**
* The reasons for which recipient email addresses should be automatically added
* to your account's suppression list
*
* @default - use account level settings
*/
readonly suppressionReasons?: SuppressionReasons;
/**
* The custom subdomain that is used to redirect email recipients to the
* Amazon SES event tracking domain
*
* @default - use the default awstrack.me domain
*/
readonly customTrackingRedirectDomain?: string;
}
/**
* TLS policy for a configuration set
*/
export enum ConfigurationSetTlsPolicy {
/**
* Messages are only delivered if a TLS connection can be established
*/
REQUIRE = 'REQUIRE',
/**
* Messages can be delivered in plain text if a TLS connection can't be established
*/
OPTIONAL = 'OPTIONAL',
}
/**
* Reasons for which recipient email addresses should be automatically added
* to your account's suppression list
*/
export enum SuppressionReasons {
/**
* Bounces and complaints
*/
BOUNCES_AND_COMPLAINTS = 'BOUNCES_AND_COMPLAINTS',
/**
* Bounces only
*/
BOUNCES_ONLY = 'BOUNCES_ONLY',
/**
* Complaints only
*/
COMPLAINTS_ONLY = 'COMPLAINTS_ONLY',
}
/**
* A configuration set
*/
export class ConfigurationSet extends Resource implements IConfigurationSet {
/**
* Use an existing configuration set
*/
public static fromConfigurationSetName(scope: Construct, id: string, configurationSetName: string): IConfigurationSet {
class Import extends Resource implements IConfigurationSet {
public readonly configurationSetName = configurationSetName;
}
return new Import(scope, id);
}
public readonly configurationSetName: string;
constructor(scope: Construct, id: string, props: ConfigurationSetProps = {}) {
super(scope, id, {
physicalName: props.configurationSetName,
});
const configurationSet = new CfnConfigurationSet(this, 'Resource', {
deliveryOptions: undefinedIfNoKeys({
sendingPoolName: props.dedicatedIpPool?.dedicatedIpPoolName,
tlsPolicy: props.tlsPolicy,
}),
name: this.physicalName,
reputationOptions: undefinedIfNoKeys({
reputationMetricsEnabled: props.reputationMetrics,
}),
sendingOptions: undefinedIfNoKeys({
sendingEnabled: props.sendingEnabled,
}),
suppressionOptions: undefinedIfNoKeys({
suppressedReasons: renderSuppressedReasons(props.suppressionReasons),
}),
trackingOptions: undefinedIfNoKeys({
customRedirectDomain: props.customTrackingRedirectDomain,
}),
});
this.configurationSetName = configurationSet.ref;
}
/**
* Adds an event destination to this configuration set
*/
public addEventDestination(id: string, options: ConfigurationSetEventDestinationOptions): ConfigurationSetEventDestination {
return new ConfigurationSetEventDestination(this, id, {
...options,
configurationSet: this,
});
}
}
function renderSuppressedReasons(suppressionReasons?: SuppressionReasons): string[] | undefined {
if (!suppressionReasons) {
return undefined;
}
switch (suppressionReasons) {
case SuppressionReasons.BOUNCES_AND_COMPLAINTS:
return ['BOUNCE', 'COMPLAINT'];
case SuppressionReasons.BOUNCES_ONLY:
return ['BOUNCE'];
case SuppressionReasons.COMPLAINTS_ONLY:
return ['COMPLAINT'];
}
}