Skip to content

Commit b166bf5

Browse files
committed
chore: wip
1 parent b2cd957 commit b166bf5

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

.stacks/core/cloud/src/cloud.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { Construct } from 'constructs'
33
import type { StackProps } from 'aws-cdk-lib'
44
import {
5+
CustomResource,
56
Duration,
67
Fn,
78
CfnOutput as Output,
@@ -302,18 +303,49 @@ export class StacksCloud extends Stack {
302303
this.redirectZones.push(hostedZone)
303304
})
304305

305-
new custom_resources.AwsCustomResource(this, 'VerifyDomainIdentity', {
306+
const domainIdentity = new custom_resources.AwsCustomResource(this, 'DomainIdentity', {
306307
onCreate: {
307308
service: 'SES',
308309
action: 'verifyDomainIdentity',
309310
parameters: {
310311
Domain: this.domain,
311312
},
312-
physicalResourceId: custom_resources.PhysicalResourceId.of('VerifyDomainIdentity'),
313+
physicalResourceId: { id: 'DomainIdentityCreation' },
313314
},
314315
policy: custom_resources.AwsCustomResourcePolicy.fromSdkCalls({ resources: custom_resources.AwsCustomResourcePolicy.ANY_RESOURCE }),
315316
})
316317

318+
// give ourselves permission to verify the domain
319+
domainIdentity.grantPrincipal.addToPrincipalPolicy(new iam.PolicyStatement({
320+
actions: ['ses:VerifyDomainIdentity'],
321+
resources: ['*'],
322+
effect: iam.Effect.ALLOW,
323+
}))
324+
325+
// Enable DKIM on the domain identity
326+
const dkimAttributes = new custom_resources.AwsCustomResource(this, 'DkimAttributes', {
327+
onCreate: {
328+
service: 'SES',
329+
action: 'verifyDomainDkim',
330+
parameters: {
331+
Domain: this.domain,
332+
},
333+
physicalResourceId: { id: 'DkimAttributesCreation' },
334+
},
335+
policy: custom_resources.AwsCustomResourcePolicy.fromSdkCalls({ resources: custom_resources.AwsCustomResourcePolicy.ANY_RESOURCE }),
336+
})
337+
338+
// Add the DKIM CNAME records to the DNS configuration
339+
const dkimTokens = dkimAttributes.getResponseField('DkimTokens')
340+
for (let i = 0; i < dkimTokens.length; i++) {
341+
new route53.CnameRecord(this, `DkimRecord${i}`, {
342+
zone: this.zone,
343+
recordName: `${dkimTokens[i]}._domainkey.${this.domain}`,
344+
domainName: `${dkimTokens[i]}.dkim.amazonses.com`,
345+
ttl: Duration.hours(1),
346+
})
347+
}
348+
317349
new route53.MxRecord(this, 'MxRecord', {
318350
zone: this.zone,
319351
recordName: this.domain,

.stacks/ide/dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
alefragnani
22
alrighty
3+
amazonses
34
amazonwebservices
45
antfu
56
applypatch
@@ -68,6 +69,7 @@ destructurable
6869
devs
6970
dinero
7071
docgen
72+
domainkey
7173
dotenv
7274
dprint
7375
encrypter

0 commit comments

Comments
 (0)