For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-aws-lambda-with-vulnerable-policy.md.
A documentation index is available at /llms.txt.
AWS Lambda permissions with wildcard actions (lambda:*) grant excessive privileges that violate the principle of least privilege, potentially allowing unauthorized operations on your Lambda functions. When wildcards are used, principals may execute unintended actions against your functions, leading to potential service disruption or data leakage. Instead of using wildcards like action = "lambda:*", specify only the precise permissions needed, such as action = "lambda:InvokeFunction" to ensure proper access controls and reduce the attack surface of your Lambda resources.
Compliant Code Examples
resource"aws_lambda_permission""allow_cloudwatch"{statement_id="AllowExecutionFromCloudWatch"action="lambda:InvokeFunction"function_name=aws_lambda_function.test_lambda.function_nameprincipal="events.amazonaws.com"source_arn="arn:aws:events:eu-west-1:111122223333:rule/RunDaily"qualifier=aws_lambda_alias.test_alias.name}resource"aws_lambda_alias""test_alias"{name="testalias"description="a sample description"function_name=aws_lambda_function.test_lambda.function_namefunction_version="$LATEST"}resource"aws_lambda_function""test_lambda"{filename="lambdatest.zip"function_name="lambda_function_name"role=aws_iam_role.iam_for_lambda.arnhandler="exports.handler"runtime="nodejs12.x"}resource"aws_iam_role""iam_for_lambda"{name="iam_for_lambda" # Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
assume_role_policy= jsonencode({Version="2012-10-17"Statement=[{Action="sts:AssumeRole"Effect="Allow"Sid=""Principal={Service="lambda.amazonaws.com"}},]})}