For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-public-lambda-via-api-gateway.md.
A documentation index is available at /llms.txt.
Lambda permissions that grant API Gateway or the public principal access with a SourceArn ending in /*/* allow any API stage and method to invoke the function. This enables broad or unintended public invocation and can result in unauthorized executions, data exposure, and increased resource consumption.
In AWS CloudFormation, check AWS::Lambda::Permission resources where Action is lambda:InvokeFunction or lambda:* and Principal is apigateway.amazonaws.com or *. The SourceArn must not equal /*/* or end with /*/*. Resources missing SourceArn or containing a trailing /*/* will be flagged. Set SourceArn to a specific execute-api ARN that includes the API ID, stage, and method to limit invocation scope.