Skip to content

Commit

Permalink
feat: also publish events to Events SNS topic (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega authored Jul 23, 2024
1 parent 048670f commit 6cc03e2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
21 changes: 17 additions & 4 deletions src/adapters/deployer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function initComponents(): Promise<AppComponents> {

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)
Expand All @@ -46,7 +47,8 @@ export async function initComponents(): Promise<AppComponents> {
})

const sns: SnsComponent = {
arn: snsArn
arn: snsArn,
eventArn: eventSnsArn
}

const deployer = createDeployerComponent({ storage, downloadQueue, fetch, logs, metrics, sns })
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down

0 comments on commit 6cc03e2

Please sign in to comment.