-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda-edge-presign.tf
More file actions
109 lines (103 loc) · 3.46 KB
/
lambda-edge-presign.tf
File metadata and controls
109 lines (103 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
module "edge_presign_alarm" {
source = "./modules/lambda_alarms"
lambda_function_name = module.edge-presign-lambda.function_name
lambda_timeout = module.edge-presign-lambda.timeout
namespace = "AWS/Lambda"
alarm_actions = [module.edge_presign_alarm_topic.arn]
ok_actions = [module.edge_presign_alarm_topic.arn]
depends_on = [module.edge-presign-lambda, module.edge_presign_alarm_topic]
providers = {
aws = aws.us_east_1
}
}
resource "aws_cloudwatch_log_metric_filter" "edge_presign_error" {
count = local.is_sandbox ? 0 : 1
name = "EdgePresignErrorFilter"
pattern = "%LambdaError%"
log_group_name = "/aws/lambda/us-east-1.${module.edge-presign-lambda.function_name}"
metric_transformation {
name = "EdgePresignErrorCount"
namespace = "EdgeLambdaInsights"
value = "1"
}
}
resource "aws_cloudwatch_metric_alarm" "edge_presign_lambda_error" {
alarm_name = "${module.edge-presign-lambda.function_name}_error_alarm"
metric_name = "EdgePresignErrorCount"
namespace = "EdgeLambdaInsights"
threshold = 0
statistic = "Sum"
period = "300"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
alarm_actions = [aws_sns_topic.alarm_notifications_topic[0].arn]
ok_actions = [module.edge_presign_alarm_topic.arn]
depends_on = [module.edge-presign-lambda, aws_sns_topic.alarm_notifications_topic[0]]
alarm_description = "Triggers when Edge Presign Lambda errors."
count = local.is_sandbox ? 0 : 1
}
module "edge_presign_alarm_topic" {
source = "./modules/sns"
sns_encryption_key_id = module.sns_encryption_key.id
topic_name = "edge_presign-alarms-topic"
topic_protocol = "lambda"
topic_endpoint = module.edge-presign-lambda.lambda_arn
depends_on = [module.sns_encryption_key]
delivery_policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Service" : "cloudwatch.amazonaws.com"
},
"Action" : [
"SNS:Publish",
],
"Condition" : {
"ArnLike" : {
"aws:SourceArn" : "arn:aws:cloudwatch:eu-west-2:${data.aws_caller_identity.current.account_id}:alarm:*"
}
}
"Resource" : "*"
}
]
})
}
module "edge-presign-lambda" {
source = "./modules/lambda_edge"
name = "EdgePresignLambda"
handler = "handlers.edge_presign_handler.lambda_handler"
iam_role_policies = [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
aws_iam_policy.ssm_access_policy.arn,
module.ndr-app-config.app_config_policy_arn,
aws_iam_policy.staging_bucket_put.arn
]
providers = {
aws = aws.us_east_1
}
bucket_names = [
module.ndr-lloyd-george-store.bucket_id,
module.ndr-document-pending-review-store.bucket_id,
module.ndr-bulk-staging-store.bucket_id
]
table_name = module.cloudfront_edge_dynamodb_table.table_name
}
resource "aws_iam_policy" "staging_bucket_put" {
name = "${terraform.workspace}_staging_bucket_put"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Action = [
"s3:PutObject"
],
Resource = [
"${module.ndr-bulk-staging-store.bucket_arn}/*",
]
}
]
})
}