Skip to content

Commit

Permalink
feat: Make email-function idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
simonknittel committed Feb 11, 2024
1 parent a487d1c commit 9c4cfa9
Show file tree
Hide file tree
Showing 14 changed files with 1,351 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-email-function.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
if: steps.email-function-node-modules-cache.outputs.cache-hit != 'true'

- name: Build email-function
run: npm run build:lambda:sqs
run: npm run build:lambda
working-directory: email-function

- name: Store email-function artifact
Expand Down
2 changes: 2 additions & 0 deletions app/src/_lib/email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { env } from "~/env.mjs";
import { type EmailConfirmationProps } from "../../../emails/emails/EmailConfirmation";
import { CustomError } from "./logging/CustomError";
import { createId } from "@paralleldrive/cuid2";

export const sendEmail = async (
to: string,
Expand All @@ -13,6 +14,7 @@ export const sendEmail = async (
const response = await fetch(env.EMAIL_FUNCTION_ENDPOINT, {
method: "POST",
body: JSON.stringify({
requestId: createId(),
to,
template,
templateProps,
Expand Down
13 changes: 7 additions & 6 deletions bruno-collection/Email function/Valid request.bru
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ post {

body:json {
{
"to": "hallo@simonknittel.de",
"template": "emailConfirmation",
"templateProps": {
"baseUrl": "http://localhost:3000",
"token": "1234567890"
}
"requestId": "clshdsp3g000108ilcpxqdh1k",
"to": "hallo@simonknittel.de",
"template": "emailConfirmation",
"templateProps": {
"baseUrl": "http://localhost:3000",
"token": "1234567890"
}
}
}
4 changes: 4 additions & 0 deletions cloudformation/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ Resources:
- config:DescribeConfigurationRecorderStatus
- config:DescribeConfigurationRecorders
- config:DescribeDeliveryChannels
- dynamodb:DescribeContinuousBackups
- dynamodb:DescribeTable
- dynamodb:DescribeTimeToLive
- dynamodb:ListTagsOfResource
- events:DescribeEventBus
- events:DescribeRule
- events:ListTagsForResource
Expand Down
2 changes: 1 addition & 1 deletion docs/setup-test-and-production.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
## 5. Set up Terraform

1. Create and populate `test.s3.tfbackend`, `prod.s3.tfbackend`, `test.tfvars` and `prod.tfvars`
2. `cd email-function && npm run build:lambda:sqs`
2. `cd email-function && npm run build:lambda`
3. Create Terraform resources

1. `AWS_PROFILE=sinister-incorporated-test aws sso login`
Expand Down
Loading

0 comments on commit 9c4cfa9

Please sign in to comment.