API Gateway Authorization Strategies
What you'll learn: How to implement custom authentication and authorization logic using Lambda authorizers and JWT authorizers in API Gateway.
The Authorization Challenge
While API keys identify who is calling your API, authorization determines what they're allowed to do. API Gateway provides two powerful strategies for custom authorization logic: Lambda authorizers (formerly custom authorizers) and JWT authorizers—both letting you enforce fine-grained access control before requests reach your backend.
Lambda Authorizers
A Lambda authorizer is a function you write that API Gateway calls before routing requests. It receives the request context (headers, tokens, etc.), validates credentials against your own authentication system, and returns an IAM policy document that grants or denies access.
Think of it as a security guard: The guard (Lambda function) checks your credentials against their list, then decides which doors (API routes) you can enter.
Lambda authorizers come in two types:
- Token-based: Validates a bearer token (like an OAuth token)
- Request-based: Evaluates multiple parameters (headers, query strings, context)
JWT Authorizers
A JWT (JSON Web Token) authorizer validates JWT tokens natively without requiring custom code. You configure API Gateway with your JWT issuer and audience, and it automatically validates signatures and claims before allowing requests through.
This is simpler and faster when you're using standard JWT-based identity providers (like Auth0, Cognito, or Okta).
When to Use Which
Use Lambda authorizers when you need custom logic (database lookups, complex rules). Use JWT authorizers when you have standard JWT tokens and want built-in validation with lower latency.
Key Takeaway: Lambda authorizers give you complete flexibility for custom authentication logic, while JWT authorizers provide fast, built-in validation for standard JWT tokens—choose based on your security requirements and token format.