@@ -53,12 +53,33 @@ resource "aws_sqs_queue" "test_queue" {
53
53
name = " test-queue"
54
54
# fifo_queue = true
55
55
# content_based_deduplication = true
56
- delay_seconds = 90
56
+ delay_seconds = 1
57
57
max_message_size = 2048
58
58
message_retention_seconds = 86400
59
59
receive_wait_time_seconds = 10
60
60
}
61
61
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
+
62
83
# Lambda resource docs:
63
84
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function
64
85
data "aws_iam_policy_document" "assume_role" {
@@ -117,12 +138,6 @@ resource "aws_lambda_function" "test_lambda" {
117
138
handler = " index.handler"
118
139
source_code_hash = data. archive_file . lambda . output_base64sha256
119
140
runtime = " nodejs20.x"
120
-
121
- # environment {
122
- # variables = {
123
- # foo = "bar"
124
- # }
125
- # }
126
141
}
127
142
128
143
resource "aws_lambda_event_source_mapping" "sqs_event_source" {
@@ -141,7 +156,12 @@ resource "aws_dynamodb_table" "test-table" {
141
156
read_capacity = 20
142
157
write_capacity = 20
143
158
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
+ }
145
165
146
166
attribute {
147
167
name = " OrderNr"
@@ -159,8 +179,16 @@ resource "aws_dynamodb_table" "test-table" {
159
179
}
160
180
161
181
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"
164
192
projection_type = " ALL"
165
193
read_capacity = 10
166
194
write_capacity = 10
@@ -171,4 +199,3 @@ resource "aws_dynamodb_table" "test-table" {
171
199
Environment = " development"
172
200
}
173
201
}
174
-
0 commit comments