-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathsst.config.ts
129 lines (115 loc) · 3.72 KB
/
sst.config.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
/// <reference path="./.sst/platform/config.d.ts" />
export default $config({
app(input) {
return {
name: "double-zero",
removal: input?.stage === "production" ? "retain" : "remove",
home: "aws",
};
},
async run() {
if (!process.env.EMAIL_IDENTITY) {
const message = "Need to set EMAIL_IDENTITY env variable.";
console.error(message);
throw Error(message);
}
const queue = new sst.aws.Queue("ZeroEmailSQS");
let service;
if (
process.env.SST_DEPLOY &&
process.env.PHX_HOST &&
process.env.DATABASE_PATH
) {
const vpc = new sst.aws.Vpc("ZeroEmailVpc");
const cluster = new sst.aws.Cluster("ZeroEmailCluster", { vpc });
const bucket = new sst.aws.Bucket("ZeroSQLiteBucket", {
public: false,
});
service = cluster.addService("ZeroEmailService", {
public: {
domain: {
name: process.env.PHX_HOST,
},
ports: [
{ listen: "80/http", forward: "4000/http" },
{ listen: "443/https", forward: "4000/http" },
],
},
environment: {
REPLICA_URL: $interpolate`s3://${bucket.name}/db`,
BUCKETNAME: bucket.name,
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY!,
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID!,
AWS_REGION: process.env.AWS_REGION!,
DATABASE_PATH: process.env.DATABASE_PATH!,
SYSTEM_EMAIL: process.env.SYSTEM_EMAIL!,
SQS_URL: queue.url,
SECRET_KEY_BASE: process.env.SECRET_KEY_BASE!,
PHX_HOST: process.env.PHX_HOST!,
},
image: {
dockerfile: "litestream.Dockerfile",
},
link: [bucket],
});
}
const topic = new sst.aws.SnsTopic("ZeroEmailSNS");
topic.subscribeQueue(queue.arn);
const configSet = new aws.sesv2.ConfigurationSet("ZeroEmailConfigSet", {
configurationSetName: "zero_email_events",
});
const exampleConfigurationSetEventDestination =
new aws.sesv2.ConfigurationSetEventDestination("ZeroEmailEvent", {
configurationSetName: configSet.configurationSetName,
eventDestinationName: "zero_email_sns",
eventDestination: {
snsDestination: {
topicArn: topic.arn,
},
enabled: true,
matchingEventTypes: [
"SEND",
"REJECT",
"BOUNCE",
"COMPLAINT",
"DELIVERY",
// TODO: Handle all these.
// "OPEN",
// "CLICK",
// "RENDERING_FAILURE",
// "DELIVERY_DELAY",
//
// Wont handle as we have internal list management.
// "SUBSCRIPTION",
],
},
});
const exampleEmailIdentity = new aws.sesv2.EmailIdentity("ZeroEmail", {
emailIdentity: process.env.EMAIL_IDENTITY || "",
configurationSetName: configSet.configurationSetName,
});
if (process.env.UNSUBSCRIBE_EMAIL) {
const unsubscribe_rule_set = new aws.ses.ReceiptRuleSet(
"ZeroUnsubscribeSet",
{ ruleSetName: "zero-unsubscribe-rule-set" },
);
const unsubscribe_rule = new aws.ses.ReceiptRule("ZeroUnsubscribeRule", {
name: "unsubscribe",
ruleSetName: unsubscribe_rule_set.ruleSetName,
recipients: [process.env.UNSUBSCRIBE_EMAIL],
enabled: true,
snsActions: [
{
position: 0,
topicArn: topic.arn,
},
],
});
const main = new aws.ses.ActiveReceiptRuleSet(
"ZeroUnsubscribeRuleActive",
{ ruleSetName: unsubscribe_rule_set.ruleSetName },
);
}
return { queue: queue.url, url: service?.url };
},
});