Description
Name the service, account or role that needs to invoke Lambda in principal. To determine the reach of a wildcard principal, also check the action and source conditions.
Potential impact
An overly broad grant can increase execution costs or let unintended events trigger the function’s data processing.
Remediation
For S3, restrict source_arn and source_account to the bucket and its owner. After updating the policy, check the statement on the actual alias. Remove any obsolete grant and test that only the intended events invoke it.
Examples
Both tasks address the same statement on the Dev alias and retain the bucket and account conditions. The second names S3 as the principal. Supply the real bucket and owner and point its event notification to the alias.
Before
- name: Configure Lambda permissions
community.aws.lambda_policy:
state: present
function_name: functionName
alias: Dev
statement_id: lambda-s3-myBucket-create-data-log
action: lambda:InvokeFunction
principal: "*"
source_arn: arn:aws:s3:::example-trigger-bucket
source_account: "123456789012"
After
- name: Configure Lambda permissions
community.aws.lambda_policy:
state: present
function_name: functionName
alias: Dev
statement_id: lambda-s3-myBucket-create-data-log
action: lambda:InvokeFunction
principal: s3.amazonaws.com
source_arn: arn:aws:s3:::example-trigger-bucket
source_account: "123456789012"