File tree Expand file tree Collapse file tree
infrastructure/terraform/modules/eventpub Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,15 +95,15 @@ async function sendToDLQ(events) {
9595 }
9696}
9797
98- exports . handler = async ( snsEvent ) => {
99- console . debug ( `Received SNS event with ${ snsEvent . Records . length } records.` ) ;
98+ exports . handler = async ( sqsEvent ) => {
99+ console . debug ( `Received SQS event with ${ sqsEvent . Records . length } records.` ) ;
100100
101101 if ( THROTTLE_DELAY_MS > 0 ) {
102102 console . info ( `Throttling enabled. Delaying processing by ${ THROTTLE_DELAY_MS } ms` ) ;
103103 await new Promise ( res => setTimeout ( res , THROTTLE_DELAY_MS ) ) ;
104104 }
105105
106- const records = snsEvent . Records . map ( record => JSON . parse ( record . Sns . Message ) ) ;
106+ const records = sqsEvent . Records . map ( record => JSON . parse ( record . body ) ) ;
107107 const validEvents = records . filter ( validateEvent ) ;
108108 const invalidEvents = records . filter ( event => ! validateEvent ( event ) ) ;
109109
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ resource "aws_lambda_function" "main" {
66 handler = " index.handler"
77 runtime = " nodejs22.x"
88 publish = true
9- memory_size = 128
9+ memory_size = 512
1010 timeout = 20
1111
1212 filename = data. archive_file . lambda . output_path
@@ -28,3 +28,18 @@ resource "aws_lambda_function" "main" {
2828 }
2929 }
3030}
31+
32+ resource "aws_lambda_event_source_mapping" "sqs_to_lambda" {
33+ event_source_arn = module. sqs_queue . sqs_queue_arn
34+ function_name = aws_lambda_function. main . function_name
35+ batch_size = 5000
36+ maximum_batching_window_in_seconds = 0
37+ function_response_types = [
38+ " ReportBatchItemFailures"
39+ ]
40+
41+ scaling_config {
42+ maximum_concurrency = 20
43+ }
44+ }
45+
Original file line number Diff line number Diff line change 1+ module "sqs_queue" {
2+ source = " ../../sqs"
3+
4+ aws_account_id = var. aws_account_id
5+ component = var. component
6+ environment = var. environment
7+ project = var. project
8+ region = var. region
9+ name = local. csi
10+ create_dlq = true
11+ sqs_kms_key_arn = var. kms_key_arn
12+ sqs_policy_overload = data. aws_iam_policy_document . allow_sns_send . json
13+ }
14+
15+ data "aws_iam_policy_document" "allow_sns_send" {
16+ statement {
17+ sid = " AllowSNSSendMessage"
18+ effect = " Allow"
19+
20+ principals {
21+ type = " Service"
22+ identifiers = [" sns.amazonaws.com" ]
23+ }
24+
25+ actions = [
26+ " sqs:SendMessage" ,
27+ ]
28+
29+ resources = [
30+ module . sqs_queue . sqs_queue_arn ,
31+ ]
32+ }
33+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ resource "aws_sns_topic_subscription" "sqs" {
2+ topic_arn = aws_sns_topic. main . arn
3+ protocol = " sqs"
4+ endpoint = module. sqs_queue . sqs_queue_arn
5+ }
You can’t perform that action at this time.
0 commit comments