API Gateway Publicly Accessible
api-gateway-public-endpoint
What this rule checks
Detects API Gateway REST APIs configured with a non-PRIVATE endpoint, i.e. reachable from the public internet.
How to fix it
- 1Use a PRIVATE endpoint type with a VPC endpoint for internal APIs
- 2For intentionally public APIs, attach an authorizer and a WAF web ACL
- 3If public access is intended, suppress this rule for the resource
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
const api = new apigateway.RestApi(this, 'Api');
api.root.addMethod('GET', new apigateway.MockIntegration());import * as apigateway from 'aws-cdk-lib/aws-apigateway';
const api = new apigateway.RestApi(this, 'Api', {
endpointConfiguration: { types: [apigateway.EndpointType.PRIVATE] },
});
api.root.addMethod('GET', new apigateway.MockIntegration());CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.
Affected resource types
AWS::ApiGateway::RestApiIntentional? Suppress this finding
Sometimes a flag is deliberate — a genuinely public endpoint, say. You can dismiss api-gateway-public-endpoint and the reason is kept in the report, not silently hidden.
In .cdk-insights.json:
{
"ignoreRules": [
{ "id": "api-gateway-public-endpoint", "reason": "Why this is intentional" }
]
}Or inline in your CDK code:
Validations.of(scope).acknowledge({
id: 'cdk-insights::api-gateway-public-endpoint',
reason: 'Why this is intentional',
});Use the rule ID api-gateway-public-endpoint shown above — not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs →
Catch this in your stack
$ npx cdk-insights scanCDK Insights runs this and 126+ other rules locally against your synthesised CDK app — free, no account, your code never leaves your machine.