Skip to content

Commit 4666dd5

Browse files
committed
fix: Work around limit in lambda policy size
Currently failing with ``` │ Error: adding Lambda Permission (arn:aws:lambda:us-east-2:591234544403:function:model-inference-development-datadog-forwarder/_aws_sagemaker_Endpoints_recs-ranker-rn-scribd-has-read-after-AllowExecutionFromCloudWatchLogs): PolicyLengthExceededException: The final policy size (20782) is bigger than the limit (20480). │ { │ RespMetadata: { │ StatusCode: 400, │ RequestID: "e220c7fb-c4c9-4b93-9f15-beba592a3afc" │ }, │ Message_: "The final policy size (20782) is bigger than the limit (20480).", │ Type: "User" │ } │ │ with module.datadog[0].aws_lambda_permission.allow_cloudwatch_logs_to_call_dd_lambda_handler["/aws/sagemaker/Endpoints/recs-ranker-rn-scribd-has-read-after"], │ on .terraform/modules/datadog/logs_monitoring_cloudwatch_log.tf line 10, in resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler": │ 10: resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" { } ```
1 parent 3678529 commit 4666dd5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

logs_monitoring_cloudwatch_log.tf

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ resource "aws_cloudwatch_log_subscription_filter" "test_lambdafunction_logfilter
77
distribution = "Random"
88
}
99

10+
// we're using wildcard sources instead of making separate grant per source
11+
// in order to avoid hitting limit of 20KB per lambda function's aggregated policy size
1012
resource "aws_lambda_permission" "allow_cloudwatch_logs_to_call_dd_lambda_handler" {
11-
for_each = { for lg in var.cloudwatch_log_groups : lg => lg }
12-
statement_id = "${substr(replace(each.value, "/", "_"), 0, 67)}-AllowExecutionFromCloudWatchLogs"
13+
statement_id = "AllowExecutionFromCloudWatchLogs"
1314
action = "lambda:InvokeFunction"
1415
function_name = aws_cloudformation_stack.datadog-forwarder.outputs.DatadogForwarderArn
1516
principal = "logs.${var.aws_region}.amazonaws.com"
16-
source_arn = "arn:aws:logs:${var.aws_region}:${var.aws_account_id}:log-group:${each.value}:*"
17+
source_arn = "arn:aws:logs:${var.aws_region}:${var.aws_account_id}:log-group:*"
1718
}

0 commit comments

Comments
 (0)