Description
For CloudWatch Logs delivery to Lambda, set the action in aws_lambda_permission to lambda:InvokeFunction.
Potential impact
A different action alone can leave log delivery broken and grant an unnecessary permission.
Remediation
Set principal to the Logs service for the Region and source_arn to the intended log group. Grant other supported actions only when required. Configure the subscription filter and verify that logs reach the function.
Examples
The second excerpt replaces lambda:DeleteFunction with invocation permission. Both reference the same log group and eu-west-1 service principal. Supply the function and log group separately.
Before
hcl
resource "aws_lambda_permission" "example" {
action = "lambda:DeleteFunction"
function_name = aws_lambda_function.logging.function_name
principal = "logs.eu-west-1.amazonaws.com"
source_arn = "${aws_cloudwatch_log_group.default.arn}:*"
}
After
hcl
resource "aws_lambda_permission" "example" {
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.logging.function_name
principal = "logs.eu-west-1.amazonaws.com"
source_arn = "${aws_cloudwatch_log_group.default.arn}:*"
}