File tree Expand file tree Collapse file tree
infrastructure/modules/lambda Expand file tree Collapse file tree Original file line number Diff line number Diff 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"
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments