AWS API Gateway limit requests from a single IP
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
AWS API Gateway is a versatile and fully managed service that allows developers to create, publish, maintain, monitor, and secure APIs at any scale. One of the essential features of API Gateway is the ability to limit requests from individual IP addresses. This capability is crucial for maintaining the quality of service by preventing abuse, managing load, and avoiding denial-of-service (DoS) attacks. In this article, we will explore methods to limit requests from a single IP using AWS API Gateway.
Rate Limiting in API Gateway
AWS offers a variety of tools and services for effectively managing and implementing rate limiting on your APIs. For API Gateway, you can use usage plans and throttling configurations to impose limits on the frequency of allowed requests. Let's break down some key concepts to understand how you can configure such limits:
Usage Plans
- Usage plans allow you to specify who can access one or more deployed API stages and methods. They enable specific request limit settings on a per-user basis.
- Each usage plan specifies:
- Rate limits (steady-state requests per second).
- Burst limits (maximum request count at a short burst).
- Quotas (daily, weekly, monthly soft limits).
Throttling
- Throttling is used to limit the number of requests that can be sent to an API Gateway method within a period. It is implemented at two levels:
- Account-level throttling limits the aggregate request rate across all APIs in an account.
- API-level throttling sets rate limits on an individual API, irrespective of the account limit.
Key Implementation Techniques
1. Configure Usage Plans:
To limit requests per IP, you first provision API keys and bind them to a use plan that specifies a rate for the IP. Follow these steps:
- Create an API key in API Gateway.
- Define a usage plan specifying the rate and burst limits.
- Associate the API with the usage plan. Use stages or specific methods as required.
2. Use Lambda Authorizers:
AWS Lambda Authorizers, also known as custom authorizers, provide a mechanism that allows you to run a Lambda function before your API Method execution. You can implement custom IP address restriction logic inside a Lambda Authorizer that will control access based on IP.
Example:
- Create a WAF web ACL (Access Control List).
- Configure rules for IP rate limiting using conditions.
- Associate your API Gateway with the WAF web ACL.
- Always use confidential information like API keys with caution.
- Implement IP filtering and rate limiting dynamically to reduce false positives.
- Monitor IP traffic regularly through logging tools such as AWS CloudWatch.
Related reading
- AWS API Gateway No 'Access-Control-Allow-Origin' header is present
- AWS API Gateway OPTIONS requests returns 500 error
- AWS API Gateway User anonymous is not authorized to execute API
- AWS API Gateway VPC Link Pricing
- AWS API Get Any Resource By ARN
- AWS Athena too slow for an api?
- AWS AssumeRole - User is not authorized to perform stsAssumeRole on resource
- AWS Certificate Manager Requested a certificate reporting 'Renewal eligibility Ineligible?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.