From a1f90512d4c1f7bb891875a974843b638e9874ee Mon Sep 17 00:00:00 2001 From: James Dinh Date: Wed, 22 Jan 2025 17:01:49 -0800 Subject: [PATCH] figuring out logic --- lib/lambda/processEmails.ts | 17 +++++++++++++---- lib/stacks/email.ts | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/lambda/processEmails.ts b/lib/lambda/processEmails.ts index 90c5f557a..fdfa99029 100644 --- a/lib/lambda/processEmails.ts +++ b/lib/lambda/processEmails.ts @@ -112,6 +112,10 @@ export const handler: Handler = async (event) => { export async function processRecord(kafkaRecord: KafkaRecord, config: ProcessEmailConfig) { console.log('before process record') + console.log("processRecord called with kafkaRecord: ", JSON.stringify(kafkaRecord, null, 2)); + const { key, value, timestamp } = kafkaRecord; + const id: string = decodeBase64WithUtf8(key); + if (kafkaRecord.topic === "aws.seatool.ksql.onemac.three.agg.State_Plan") { const record = JSON.parse(decodeBase64WithUtf8(kafkaRecord.value)) console.log('inside process record', record) @@ -121,7 +125,14 @@ export async function processRecord(kafkaRecord: KafkaRecord, config: ProcessEma //send email console.log(safeSeatoolRecord.data?.cmsStatus, "seatool status is withdrawn") - // await processAndSendEmails(record, id, config); + console.log(record,id, config) + + try { + await processAndSendEmails(record, id, config); + } catch (error) { + console.error("Error processing record:", JSON.stringify(error, null, 2)); + throw error; + } } return } @@ -136,13 +147,11 @@ export async function processRecord(kafkaRecord: KafkaRecord, config: ProcessEma // then we can get the email template and send it - console.log("processRecord called with kafkaRecord: ", JSON.stringify(kafkaRecord, null, 2)); - const { key, value, timestamp } = kafkaRecord; + if (typeof key !== "string") { console.log("key is not a string ", JSON.stringify(key, null, 2)); throw new Error("Key is not a string"); } - const id: string = decodeBase64WithUtf8(key); if (!value) { console.log("Tombstone detected. Doing nothing for this event"); diff --git a/lib/stacks/email.ts b/lib/stacks/email.ts index 84536e30e..b7cb258ec 100644 --- a/lib/stacks/email.ts +++ b/lib/stacks/email.ts @@ -222,7 +222,7 @@ export class Email extends cdk.NestedStack { alarm.addAlarmAction(new cdk.aws_cloudwatch_actions.SnsAction(alarmTopic)); - new CfnEventSourceMapping(this, "SinkSESTrigger1", { + new CfnEventSourceMapping(this, "SinkSESTrigger5", { batchSize: 1, enabled: true, selfManagedEventSource: { @@ -250,7 +250,7 @@ export class Email extends cdk.NestedStack { }, }); - new CfnEventSourceMapping(this, "SinkSESTrigger2", { + new CfnEventSourceMapping(this, "SinkSESTrigger6", { batchSize: 1, enabled: true, selfManagedEventSource: {