Skip to content

Commit

Permalink
async-update queue + subscription (#2)
Browse files Browse the repository at this point in the history
* async-update queue + subscription

* Misc fixes
  • Loading branch information
joshgarde authored Jun 21, 2023
1 parent 89bbf31 commit 16019d1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
7 changes: 7 additions & 0 deletions terraform/database_rds.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@ resource "aws_ssm_parameter" "db_app_password" {
value = random_password.app_password.result
overwrite = true
}

resource "aws_ssm_parameter" "db_name" {
name = "${local.service_path}/db-name"
type = "String"
value = var.db_name
overwrite = true
}
61 changes: 56 additions & 5 deletions terraform/messaging.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,18 @@ resource "aws_kms_key_policy" "ingest_sns" {
})
}

resource "aws_kms_key" "job_update" {
description = "${local.resource_prefix}-job-update"
resource "aws_kms_key" "product_create" {
description = "${local.resource_prefix}-product-create"
deletion_window_in_days = 10
}

resource "aws_kms_key" "product_update" {
description = "${local.resource_prefix}-product-update"
deletion_window_in_days = 10
}

resource "aws_kms_key" "async_update" {
description = "${local.resource_prefix}-async-update"
deletion_window_in_days = 10
}

Expand Down Expand Up @@ -112,9 +122,16 @@ resource "aws_sns_topic_policy" "ingest_topic_write" {
})
}

resource "aws_sns_topic" "job_update" {
name = "${local.resource_prefix}-job-update-topic"
kms_master_key_id = aws_kms_key.job_update.id
resource "aws_sns_topic" "product_update" {
name = "${local.resource_prefix}-product-update-topic"
kms_master_key_id = aws_kms_key.product_update.id
}

resource "aws_sns_topic_subscription" "async_update_target" {
topic_arn = aws_sns_topic.product_update.arn
protocol = "sqs"
endpoint = aws_sqs_queue.async_update.arn
raw_message_delivery = true
}

// - SQS
Expand Down Expand Up @@ -144,3 +161,37 @@ resource "aws_sqs_queue_policy" "ingest" {
}]
})
}

resource "aws_sqs_queue" "product_create" {
name = "${local.resource_prefix}-product-create-queue"
kms_master_key_id = aws_kms_key.product_create.id
message_retention_seconds = 7 * 24 * 60 * 60 # 1 week
visibility_timeout_seconds = 12 * 60 * 60 # 12 hours
}

resource "aws_sqs_queue" "async_update" {
name = "${local.resource_prefix}-async-update-queue"
kms_master_key_id = aws_kms_key.async_update.id
message_retention_seconds = 7 * 24 * 60 * 60 # 1 week
visibility_timeout_seconds = 12 * 60 * 60 # 12 hours
}

resource "aws_sqs_queue_policy" "async_update" {
queue_url = aws_sqs_queue.async_update.url
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = {
Service = "sns.amazonaws.com"
}
Action = "sqs:SendMessage"
Resource = aws_sqs_queue.async_update.arn
Condition = {
ArnEquals = {
"aws:SourceArn" = aws_sns_topic.product_update.arn
}
}
}]
})
}

0 comments on commit 16019d1

Please sign in to comment.