From 69363cf96f563a21a146cee89639ab33e3af36f9 Mon Sep 17 00:00:00 2001 From: Alejo Thomas Ortega Date: Tue, 23 Jul 2024 15:45:06 -0300 Subject: [PATCH] feat: also publish events to Events SNS topic --- src/adapters/deployer/index.ts | 21 +++++++++++++++++---- src/components.ts | 4 +++- src/types.ts | 2 +- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/adapters/deployer/index.ts b/src/adapters/deployer/index.ts index ead6e17..a09a750 100644 --- a/src/adapters/deployer/index.ts +++ b/src/adapters/deployer/index.ts @@ -40,12 +40,12 @@ export function createDeployerComponent( logger.info('Entity stored', { entityId: entity.entityId, entityType: entity.entityType }) + const deploymentToSqs: DeploymentToSqs = { + entity, + contentServerUrls: servers + } // send sns if (components.sns.arn) { - const deploymentToSqs: DeploymentToSqs = { - entity, - contentServerUrls: servers - } const receipt = await sns .publish({ TopicArn: components.sns.arn, @@ -57,6 +57,19 @@ export function createDeployerComponent( SequenceNumber: receipt.SequenceNumber as any }) } + + if (components.sns.eventArn) { + const receipt = await sns + .publish({ + TopicArn: components.sns.eventArn, + Message: JSON.stringify(deploymentToSqs) + }) + .promise() + logger.info('Notification sent to events SNS', { + MessageId: receipt.MessageId as any, + SequenceNumber: receipt.SequenceNumber as any + }) + } await markAsDeployed() }) } else { diff --git a/src/components.ts b/src/components.ts index aea555c..af249b0 100644 --- a/src/components.ts +++ b/src/components.ts @@ -34,6 +34,7 @@ export async function initComponents(): Promise { const bucket = await config.getString('BUCKET') const snsArn = await config.getString('SNS_ARN') + const eventSnsArn = await config.getString('EVENTS_SNS_ARN') const storage = bucket ? await createAwsS3BasedFileSystemContentStorage({ fs, config }, bucket) @@ -46,7 +47,8 @@ export async function initComponents(): Promise { }) const sns: SnsComponent = { - arn: snsArn + arn: snsArn, + eventArn: eventSnsArn } const deployer = createDeployerComponent({ storage, downloadQueue, fetch, logs, metrics, sns }) diff --git a/src/types.ts b/src/types.ts index 461a6d1..bcec10e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -30,7 +30,7 @@ export type BaseComponents = { sns: SnsComponent } -export type SnsComponent = { arn?: string } +export type SnsComponent = { arn?: string; eventArn?: string } // components used in runtime export type AppComponents = BaseComponents & {