Skip to content

Commit d164e86

Browse files
committed
Remove duplicate DLQ and add trigger and alarms for lambda
1 parent 50e8c2b commit d164e86

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

infrastructure/lambda-pdf-stitching.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,56 @@ module "pdf-stitching-lambda" {
1313
rest_api_id = null
1414
api_execution_arn = null
1515
is_invoked_from_gateway = false
16+
}
17+
18+
resource "aws_lambda_event_source_mapping" "pdf-stitching-lambda" {
19+
event_source_arn = module.sqs-stitching-queue.arn
20+
function_name = module.pdf-stitching-lambda.lambda_arn
21+
22+
depends_on [
23+
module.pdf-stitching-lambda
24+
module.sqs-stitching
25+
]
26+
}
27+
28+
module "pdf-stitching-lambda-alarms" {
29+
source = "modules/lambda_alarms
30+
lambda_function_name = module.pdf-stitching-lambda.function_name
31+
lambda_timeout = module.pdf-stitching-lambda.timeout
32+
lambda_name = "pdf-stitching-lambda"
33+
namespace = "AWS/Lambda"
34+
alarm_actions = [module.pdf-stitching-alarm-topic.arn]
35+
ok_actions = [module.pdf-stitching-alarm-topic.arn]
36+
depends_on = [module.pdf-stitching-lambda, module.pdf-stitching-alarm-topic]
37+
}
38+
39+
module "pdf-stitching-alarm-topic" {
40+
source = "./modules/sns"
41+
sns_encryption_key_id = module.sns_encryption_key.id
42+
current_account_id = data.aws_caller_identity.current.account_id
43+
topic_name = "pdf-stitching-alarm-topic"
44+
topic_protocol = "lambda"
45+
topic_endpoint = module.pdf-stitching-lambda.lambda_arn
46+
delivery_policy = jsonencode({
47+
"Version" : "2012-10-17",
48+
"Statement" : [
49+
{
50+
"Effect" : "Allow",
51+
"Principal" : {
52+
"Service" : "cloudwatch.amazonaws.com"
53+
},
54+
"Action" : [
55+
"SNS:Publish",
56+
],
57+
"Condition" : {
58+
"ArnLike" : {
59+
"aws:SourceArn" : "arn:aws:cloudwatch:eu-west-2:${data.aws_caller_identity.current.account_id}:alarm:*"
60+
}
61+
}
62+
"Resource" : "*"
63+
}
64+
]
65+
})
66+
67+
depends_on = [module.pdf-stitching-lambda, module.sns_encryption_key]
1668
}

infrastructure/sqs-stitching-dlq.tf

Lines changed: 0 additions & 10 deletions
This file was deleted.

infrastructure/sqs-stitching.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ module "sqs-stitching-queue" {
88
max_visibility = 601
99
enable_deduplication = true
1010
enable_fifo = true
11+
enable_dlq = true
1112
}

0 commit comments

Comments
 (0)