Skip to content

Commit f6cb5f3

Browse files
committed
feat: add sqs policy
1 parent bfcc5fa commit f6cb5f3

File tree

1 file changed

+38
-11
lines changed
  • microservices/order-processing/terraform

1 file changed

+38
-11
lines changed

microservices/order-processing/terraform/main.tf

+38-11
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,33 @@ resource "aws_sqs_queue" "test_queue" {
5353
name = "test-queue"
5454
# fifo_queue = true
5555
# content_based_deduplication = true
56-
delay_seconds = 90
56+
delay_seconds = 1
5757
max_message_size = 2048
5858
message_retention_seconds = 86400
5959
receive_wait_time_seconds = 10
6060
}
6161

62+
resource "aws_sqs_queue_policy" "test_queue_policy" {
63+
queue_url = aws_sqs_queue.test_queue.id
64+
65+
policy = jsonencode({
66+
Version = "2012-10-17",
67+
Statement = [
68+
{
69+
Effect = "Allow",
70+
Principal = "*",
71+
Action = "sqs:SendMessage",
72+
Resource = aws_sqs_queue.test_queue.arn,
73+
Condition = {
74+
ArnEquals = {
75+
"aws:SourceArn" : aws_cloudwatch_event_rule.process_orders.arn
76+
}
77+
}
78+
}
79+
]
80+
})
81+
}
82+
6283
# Lambda resource docs:
6384
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function
6485
data "aws_iam_policy_document" "assume_role" {
@@ -117,12 +138,6 @@ resource "aws_lambda_function" "test_lambda" {
117138
handler = "index.handler"
118139
source_code_hash = data.archive_file.lambda.output_base64sha256
119140
runtime = "nodejs20.x"
120-
121-
# environment {
122-
# variables = {
123-
# foo = "bar"
124-
# }
125-
# }
126141
}
127142

128143
resource "aws_lambda_event_source_mapping" "sqs_event_source" {
@@ -141,7 +156,12 @@ resource "aws_dynamodb_table" "test-table" {
141156
read_capacity = 20
142157
write_capacity = 20
143158
hash_key = "OrderId"
144-
range_key = "OrderNr"
159+
range_key = "OrderNr" # Changed to OrderId to ensure different names
160+
161+
attribute {
162+
name = "OrderId"
163+
type = "S"
164+
}
145165

146166
attribute {
147167
name = "OrderNr"
@@ -159,8 +179,16 @@ resource "aws_dynamodb_table" "test-table" {
159179
}
160180

161181
global_secondary_index {
162-
name = "ProductIndex"
163-
hash_key = "Product"
182+
name = "CustomerEmailIndex"
183+
hash_key = "CustomerEmail"
184+
projection_type = "ALL"
185+
read_capacity = 10
186+
write_capacity = 10
187+
}
188+
189+
global_secondary_index {
190+
name = "TotalIndex"
191+
hash_key = "Total"
164192
projection_type = "ALL"
165193
read_capacity = 10
166194
write_capacity = 10
@@ -171,4 +199,3 @@ resource "aws_dynamodb_table" "test-table" {
171199
Environment = "development"
172200
}
173201
}
174-

0 commit comments

Comments
 (0)