Skip to content

Commit 0fa8419

Browse files
committed
chore: wip
1 parent ea0103c commit 0fa8419

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
lines changed

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

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class StacksCloud extends Stack {
5656
publicBucket: s3.Bucket
5757
privateBucket: s3.Bucket
5858
logBucket: s3.Bucket | undefined
59-
emailBucket?: s3.Bucket
59+
emailBucket: s3.Bucket
6060
fileSystem?: efs.FileSystem | undefined
6161
accessPoint?: efs.AccessPoint | undefined
6262
}
@@ -354,19 +354,14 @@ export class StacksCloud extends Stack {
354354
autoDeleteObjects: true,
355355
})
356356

357-
let emailBucket: s3.Bucket | undefined
358-
if (isProductionDeployment()) {
359-
emailBucket = new s3.Bucket(this, 'EmailBucket', {
360-
bucketName: `${this.domain}-email`,
361-
versioned: true,
362-
removalPolicy: RemovalPolicy.DESTROY,
363-
autoDeleteObjects: true,
364-
})
365-
}
357+
const emailBucket: s3.Bucket = new s3.Bucket(this, 'EmailBucket', {
358+
bucketName: `${this.domain}-email`,
359+
versioned: true,
360+
removalPolicy: RemovalPolicy.DESTROY,
361+
autoDeleteObjects: true,
362+
})
366363

367-
// Create an S3 bucket for CloudFront access logs
368364
let logBucket: s3.Bucket | undefined
369-
370365
if (config.cloud.cdn?.enableLogging) {
371366
logBucket = new s3.Bucket(this, 'LogBucket', {
372367
bucketName: `${this.domain}-logs-${appEnv}`,
@@ -579,6 +574,61 @@ export class StacksCloud extends Stack {
579574
recordName: `mail.${this.domain}`,
580575
values: ['v=spf1 include:amazonses.com ~all'],
581576
})
577+
578+
const lambdaFunction = new lambda.Function(this, 'SesForwarder', {
579+
description: 'The Stacks Email Forwarder',
580+
runtime: lambda.Runtime.NODEJS_18_X,
581+
handler: 'index.handler',
582+
code: lambda.Code.fromAsset(path.join(__dirname, '/email-forwarder.zip')),
583+
})
584+
585+
const ruleSet = new ses.CfnReceiptRuleSet(this, 'RuleSet', {
586+
ruleSetName: 'EmailForwardingRuleSet',
587+
})
588+
589+
new ses.CfnReceiptRule(this, 'Rule', {
590+
rule: {
591+
name: 'EmailForwardingRule',
592+
recipients: ['chrisbreuer93@gmail.com'], // replace with your email addresses
593+
actions: [
594+
{
595+
s3Action: {
596+
bucketName: this.storage.emailBucket.bucketName,
597+
objectKeyPrefix: 'email',
598+
},
599+
},
600+
{
601+
lambdaAction: {
602+
functionArn: lambdaFunction.functionArn,
603+
invocationType: 'Event',
604+
},
605+
},
606+
],
607+
enabled: true,
608+
scanEnabled: true,
609+
},
610+
ruleSetName: ruleSet.ruleSetName as string,
611+
})
612+
613+
// Grant SES permission to write to the S3 bucket
614+
this.storage.emailBucket.addToResourcePolicy(new iam.PolicyStatement({
615+
principals: [new iam.ServicePrincipal('ses.amazonaws.com')],
616+
actions: ['s3:PutObject'],
617+
resources: [this.storage.emailBucket.arnForObjects('*')],
618+
conditions: {
619+
StringEquals: {
620+
'aws:Referer': this.account,
621+
},
622+
},
623+
}))
624+
625+
// Grant the Lambda function permission to read from the S3 bucket
626+
this.storage.emailBucket.grantRead(lambdaFunction)
627+
628+
// Grant SES permission to invoke the Lambda function
629+
lambdaFunction.addPermission('InvokeBySES', {
630+
principal: new iam.ServicePrincipal('ses.amazonaws.com'),
631+
})
582632
}
583633

584634
additionalBehaviors(): Record<string, cloudfront.BehaviorOptions> {
3.7 KB
Binary file not shown.

.stacks/core/strings/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"macroable": "^7.0.2",
7171
"pluralize": "^8.0.0",
7272
"slugify": "^1.6.6",
73+
"string-ts": "^0.5.1",
7374
"title-case": "^4.0.0",
7475
"validator": "^13.11.0"
7576
},

bun.lockb

-299 KB
Binary file not shown.

0 commit comments

Comments
 (0)