How Does AWS API Gateway Protect Your APIs? Understanding API Security in AWS

Learn how Amazon API Gateway protects APIs using authentication, authorization, throttling, resource policies, API keys, and AWS WAF. Understand how these security features work together, explore practical examples, and discover how to build secure and scalable APIs using AWS services.

lets learn

Imagine you have developed a web application where users can register, log in, view their profiles, and submit information.
Your application communicates with the backend through APIs.
For example:
  •  POST /register  – Register a new user.
  •  POST /login  – Authenticate a user.
  •  GET /profile  – Retrieve user information.
  •  POST /orders  – Place an order.
Now, imagine someone discovers your API endpoints and starts sending thousands of requests.
What if someone tries to access another user's information? What if an attacker sends repeated requests to overload your application?
Simply creating an API is not enough. You also need to protect it.
This is where Amazon API Gateway becomes useful.
Amazon API Gateway is a managed AWS service that allows developers to create, publish, secure, monitor, and manage APIs.
It acts as an entry point between clients and backend services such as AWS Lambda, EC2, and other applications.
But how exactly does it protect your APIs?
Let's understand the different security mechanisms.

2. How Does AWS API Gateway Work?

Before discussing security, let's understand the basic architecture.
Consider a simple serverless application.
A user sends a request from a browser or mobile application.
The request reaches API Gateway, which receives and processes it before forwarding it to the backend.
For example:
Client → API Gateway → AWS Lambda → DynamoDB
Here is what happens:
  1. A user sends an HTTP request to an API endpoint.
  1. API Gateway receives the request.
  1. It applies the configured security and access-control mechanisms.
  1. If the request passes the required checks, API Gateway forwards it to the backend.
  1. AWS Lambda processes the request.
  1. Lambda interacts with DynamoDB if necessary.
  1. The response travels back to the client through API Gateway.
The important point is that API Gateway acts as a controlled entry point to your backend.
Instead of allowing clients to communicate directly with your backend services, you can manage access through API Gateway.

3. Authentication and Authorization

One of the most important responsibilities of API security is ensuring that only authorized users can access protected resources.
However, authentication and authorization are two different concepts.

What Is Authentication?

Authentication answers:
Who are you?
For example, when a user logs into an application using an email address and password, the application verifies their identity.
API Gateway supports different mechanisms for authentication.
Some common options include:
A. AWS IAM Authentication
IAM authentication is useful when you want to control access through AWS identities and permissions.
API Gateway can use AWS Signature Version 4 (SigV4) to verify signed requests.
For example, if an application running on an EC2 instance needs to call an API, it can use an IAM role to obtain temporary credentials and sign its API requests.
This avoids storing permanent AWS credentials directly in the application.
B. JWT Authorization
JSON Web Tokens (JWTs) are commonly used in applications where users log in and receive an access token.
For example:
  1. A user logs into your application.
  1. The authentication system verifies the credentials.
  1. It generates a JWT.
  1. The client sends that token with subsequent API requests.
  1. API Gateway validates the token using a configured JWT authorizer.
If the token is invalid or expired, the request is rejected.
JWT authorization is supported by API Gateway HTTP APIs.
C. Lambda Authorizer
Sometimes, your authentication requirements are more complex.
For example, you might want to verify a custom token, check a database, or apply organization-specific access rules.
In such cases, you can use a Lambda authorizer.
A Lambda authorizer is a Lambda function that evaluates incoming requests and determines whether they should be allowed or denied.
For example:
  • The client sends a request with an authentication token.
  • API Gateway invokes the Lambda authorizer.
  • The Lambda function validates the token.
  • It returns an authorization decision.
  • API Gateway allows or rejects the request based on that decision.
This provides flexibility when built-in authorization options are not sufficient.

What Is Authorization?

Authorization answers:
What are you allowed to access?
Imagine an application with two types of users:
  • Admin
  • Normal User
Both users can successfully log in, but they should not have the same permissions.
For example:
API Endpoint
Admin
Normal User
GET /profile
Allowed
Allowed
GET /users
Allowed
Denied
DELETE /users/{id}
Allowed
Denied
POST /orders
Allowed
Allowed
Authentication verifies the user's identity, while authorization determines what that user can do.
Important: Authentication alone does not guarantee that users can access only their own data. Your backend must also enforce resource-level permissions, such as checking whether the requested profile or order belongs to the authenticated user.

4. Throttling and Rate Limiting

What happens if someone sends thousands of requests to your API within a few seconds?
Your backend could become overloaded, increasing costs and affecting legitimate users.
API Gateway provides throttling controls to help manage incoming traffic.

What Is Throttling?

Throttling limits the number of requests that an API can process within a particular period.
For example, suppose you configure an API with:
  • Rate: 100 requests per second.
  • Burst: 200 requests.
The rate represents the target request-processing rate, while the burst setting controls the temporary capacity for handling short traffic spikes.
If clients send too many requests, API Gateway can return:
HTTP 429 – Too Many Requests
This tells the client that it has exceeded the configured request limit.

Why Is It Important?

Imagine you have an online registration application.
Normally, 50 students might access your application every second.
But when registration opens, thousands of students may try to access it simultaneously.
Throttling helps control traffic and protects your backend from excessive requests.
However, throttling is not a complete DDoS protection solution. For broader protection against malicious traffic, you should consider AWS WAF and AWS Shield.

5. API Keys and Usage Plans

Suppose you are developing an API that different applications or external developers can access.
You may want to identify consumers and control their usage.
This is where API keys and usage plans can help.

What Is an API Key?

An API key is a value provided to a client application to identify it when making API requests.
For example:
GET /products HTTP/1.1
Host: example.execute-api.ap-south-1.amazonaws.com
x-api-key: YOUR_API_KEY
API Gateway can use this key to identify the API consumer and associate requests with a usage plan.

What Is a Usage Plan?

A usage plan allows you to configure:
  • Request throttling.
  • Quotas.
  • API key associations.
For example:
Consumer
Daily Request Quota
Basic Plan
1,000 requests
Standard Plan
10,000 requests
Premium Plan
50,000 requests
This can help you manage API consumption for different customers.
Important: API keys are not a replacement for authentication or authorization. They should not be treated as proof of user identity or used as the only security mechanism for sensitive APIs.
Also, usage plans and API key functionality are primarily associated with API Gateway REST APIs.

6. Resource Policies

Sometimes, you don't want your API to be accessible from everywhere.
For example, imagine you have an internal company API that should only be accessed from specific AWS accounts or networks.
API Gateway resource policies allow you to control access to an API using policy-based rules.
You can configure policies to:
  • Allow requests from specific IP addresses.
  • Deny requests from certain IP ranges.
  • Restrict access to specific AWS accounts.
  • Control access based on supported AWS principal and network conditions.

Example

Suppose your company API should only accept requests from this IP address:
 203.0.113.10 
You can configure a resource policy that allows requests from that IP address and denies requests from other sources.
This provides another layer of access control before requests reach your backend.
Resource policies are particularly useful when you need network-based restrictions or cross-account access control.

7. Protecting APIs Using AWS WAF

Authentication and throttling are useful, but what if someone sends malicious requests designed to exploit your application?
For example:
  • SQL injection attempts.
  • Cross-site scripting (XSS) attempts.
  • Suspicious request patterns.
  • Requests from known malicious IP addresses.
For additional protection, you can integrate AWS WAF (Web Application Firewall) with supported API Gateway REST APIs.
AWS WAF examines incoming HTTP requests and evaluates them against configured rules.
For example, you can create rules to:
  • Block requests containing suspicious patterns.
  • Restrict traffic from specific IP addresses.
  • Apply rate-based rules to limit excessive requests.
  • Use managed rule groups to detect common web application attacks.

Example

Imagine an attacker sends repeated requests containing suspicious SQL injection patterns.
AWS WAF can inspect these requests and block those that match your configured security rules.
This helps prevent malicious traffic from reaching your API.
Important: AWS WAF is an additional security layer. It does not replace authentication, authorization, or secure backend development.

8. HTTPS and TLS Encryption

Another important part of API security is protecting data while it travels across the network.
Imagine a user sends login credentials to your API.
Without encryption, sensitive information could potentially be exposed during transmission.
API Gateway supports HTTPS endpoints using TLS encryption.
TLS helps protect communication between clients and API Gateway.
For example:
http://example.com/login
This connection does not provide TLS encryption.
Whereas:
https://example.com/login
uses HTTPS and protects data during transmission.
You can also configure custom domain names and use AWS Certificate Manager (ACM) to manage SSL/TLS certificates.
Always use HTTPS when exposing APIs that handle sensitive information.

9. API Gateway vs Backend Security: Who Does What?

An important thing to understand is that API Gateway does not handle every security responsibility.
It provides several security controls at the API entry point, but your backend application must also enforce security.
Consider the following responsibilities:
Security Requirement
Responsible Component
Validate JWT tokens
API Gateway JWT Authorizer
Verify IAM-signed requests
API Gateway IAM Authorization
Apply request throttling
API Gateway
Block malicious HTTP requests
AWS WAF
Encrypt communication
HTTPS / TLS
Check user ownership of data
Backend Application
Validate business rules
Backend Application
Secure database access
IAM and Database Security
Store application secrets
AWS Secrets Manager
For example, API Gateway may verify that a user has a valid JWT.
However, your Lambda function should still verify whether that user is allowed to access a particular order or customer record.
Security should be implemented across the entire application, not just at the API entry point.

10. Practical Example: Building a Secure Student Registration API

Let's combine these concepts into a practical architecture.
Imagine you are developing a student registration application using AWS.
The architecture looks like this:
Student Application → API Gateway → Lambda → DynamoDB
You can protect this application using multiple security mechanisms.
Security Feature
How It Helps
JWT Authorization
Verifies the identity of students
Throttling
Controls excessive incoming requests
AWS WAF
Filters malicious HTTP requests
HTTPS
Protects data during transmission
IAM Roles
Controls Lambda access to DynamoDB
Backend Validation
Prevents unauthorized registrations
CloudWatch
Helps monitor API activity and errors

How Does a Request Work?

  1. A student logs into the application.
  1. The authentication service provides a JWT.
  1. The student submits a registration request.
  1. API Gateway validates the JWT.
  1. API Gateway applies the configured throttling and other security controls.
  1. If the request passes the required checks, it reaches Lambda.
  1. Lambda validates the student's registration details.
  1. Lambda uses its IAM execution role to communicate with DynamoDB.
  1. The response is returned to the student through API Gateway.
This architecture provides multiple layers of security without requiring you to build every security mechanism from scratch.

11. Conclusion

Amazon API Gateway is more than just an entry point for backend services. It provides several important features that help developers build secure, scalable, and manageable APIs.
Let's quickly summarize what we learned:
  • Authentication and Authorization: Control who can access your APIs and what they can do.
  • Throttling: Manage excessive incoming requests.
  • API Keys and Usage Plans: Identify API consumers and manage their usage.
  • Resource Policies: Restrict API access based on supported network and AWS identity conditions.
  • AWS WAF: Protect APIs against common web application attacks.
  • HTTPS/TLS: Encrypt communication between clients and APIs.
However, remember that API Gateway alone cannot make an application completely secure.
You should combine API Gateway security features with IAM permissions, backend validation, secure database access, and proper monitoring.
The goal is simple: Every request should be authenticated when required, authorized correctly, validated properly, and allowed to access only the resources it needs.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article