-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsst.config.ts
94 lines (84 loc) · 2.54 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
/// <reference path="./.sst/platform/config.d.ts" />
const dns = {
zoneId: 'Z01626782YYNKBXBBY87S',
name: 'labs.webamboos.dev',
}
export default $config({
app(input) {
return {
name: 'iot',
removal: input?.stage === 'production' ? 'retain' : 'remove',
home: 'aws',
}
},
async run() {
const stagePrefix = $app.stage === 'production' ? '' : `${$app.stage}.`
const iotDomain = `iot.${stagePrefix}${dns.name}`
const iotCertificate = new aws.acm.Certificate('IoTCertificate', {
domainName: iotDomain,
validationMethod: 'DNS',
})
const validation = iotCertificate.domainValidationOptions
.apply(domainValidationOptions => {
return domainValidationOptions.map((options, i) => {
return new aws.route53.Record(`IoTValidationRecord${i + 1}`, {
allowOverwrite: true,
name: options.resourceRecordName,
type: options.resourceRecordType,
zoneId: dns.zoneId,
ttl: 60,
records: [options.resourceRecordValue],
})
})
})
.apply(records => {
return new aws.acm.CertificateValidation(
'IoTCertificateValidation',
{
certificateArn: iotCertificate.arn,
},
{ dependsOn: [...records] }
)
})
new aws.iot.DomainConfiguration(
'IoTDomain',
{
domainName: iotDomain,
name: `${$app.stage}_iot_domain`,
serverCertificateArns: [iotCertificate.arn],
status: 'ENABLED',
tlsConfig: {
// https://docs.aws.amazon.com/iot/latest/developerguide/iot-endpoints-tls-config.html
securityPolicy: 'IoTSecurityPolicy_TLS12_1_2_2022_10',
},
},
{ dependsOn: [iotCertificate, validation] }
)
const iotEndpoint = aws.iot.getEndpoint({ endpointType: 'iot:Data-ATS' })
new aws.route53.Record('IoTEndpointAlias', {
name: iotDomain,
type: aws.route53.RecordType.CNAME,
zoneId: dns.zoneId,
records: $output(iotEndpoint).apply(e => [e.endpointAddress]),
ttl: 3600,
})
const iot = new sst.Linkable('IoT', {
properties: {
Endpoint: iotDomain,
},
include: [sst.aws.permission({ actions: ['iot:*'], resources: ['*'] })],
})
const iotApi = new sst.aws.Function('IoTAPI', {
handler: 'services/api/src/server.handler',
link: [iot],
url: {
cors: false,
authorization: 'iam',
},
})
return {
IoTDomain: iotDomain,
IoTAPI: iotApi.url,
}
},
})