Skip to content

Commit 836115f

Browse files
committed
CCM-6250: add edge lambda cap
1 parent 5233fa8 commit 836115f

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

infrastructure/modules/lambda/data_iam_policy_document_put_logs.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@ data "aws_iam_policy_document" "put_logs" {
1414
]
1515
}
1616

17+
dynamic "statement" {
18+
# Lambda@Edge logs are logged into Log Groups in the region of the edge location
19+
# that executes the code. Because of this, we need to allow the lambda role to create
20+
# Log Groups in other regions
21+
for_each = var.lambda_at_edge ? [1] : []
22+
content {
23+
sid = "AllowLambdaAtEdgeLogging"
24+
effect = "Allow"
25+
26+
actions = [
27+
"logs:CreateLogStream",
28+
"logs:PutLogEvents",
29+
"logs:CreateLogGroup",
30+
]
31+
32+
resources = [
33+
format(
34+
"arn:aws:logs:us-east-1:%s:log-group:/aws/lambda/%s:*",
35+
var.aws_account_id,
36+
var.function_name,
37+
)
38+
]
39+
}
40+
}
41+
1742
statement {
1843
sid = "KMSCloudwatchKeyAccess"
1944
effect = "Allow"

infrastructure/modules/lambda/lambda_function.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ resource "aws_lambda_function" "main" {
2222
layers = compact(concat(
2323
var.layers,
2424
[
25-
var.enable_lambda_insights ? "arn:aws:lambda:${var.region}:580247275435:layer:LambdaInsightsExtension:53" : null
25+
var.enable_lambda_insights && var.lambda_at_edge == false ? "arn:aws:lambda:${var.region}:580247275435:layer:LambdaInsightsExtension:53" : null
2626
]
2727
))
2828

infrastructure/modules/lambda/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,9 @@ variable "enable_lambda_insights" {
212212
description = "Enable the lambda insights layer, this must be disabled for lambda@edge usage"
213213
default = true
214214
}
215+
216+
variable "lambda_at_edge" {
217+
type = bool
218+
description = "Enable the lambda insights layer, this must be disabled for lambda@edge usage"
219+
default = false
220+
}

0 commit comments

Comments
 (0)