Auth, CORS, Throttling & Limits
Lock down your API, let your web app call it, and know the limits that shape your design.
Authentication options
| Option | Use it for |
|---|---|
| JWT authorizer (HTTP API) | Users signed in through Amazon Cognito, Auth0, Okta, or any OIDC provider |
| IAM authorization | Calls from other AWS services or backends that have AWS credentials |
| Lambda authorizer | Custom logic, such as checking an API key against your own database |
CORS in one paragraph
Browsers block a page on app.example.com from calling api.example.com unless the API says it's allowed. That
permission is CORS. In an HTTP API you set allowed origins, methods, and headers in the CORS settings, and
API Gateway answers the browser's pre-flight OPTIONS request for you.
Access-Control-Allow-Origin: * is fine for public, read-only data. For anything that sends cookies or user
tokens, list your real front-end origin instead.
Throttling
Set rate and burst limits per stage or per route, so a buggy client looping on your API can't run up your bill.
Throttled callers receive 429 Too Many Requests.
Limits worth knowing
- Integration timeout: about 30 seconds (29 seconds by default for REST APIs). Long jobs should return right away and finish in the background, for example via SQS or Step Functions.
- Payload size: 10 MB per request. For bigger files, upload directly to S3 with a presigned URL.
Pricing
You pay per million requests, and HTTP APIs cost noticeably less than REST APIs. Check the API Gateway pricing page for current numbers.
Key takeaways
- Use JWT authorizers for signed-in users, IAM for AWS callers, and Lambda authorizers for custom checks.
- CORS lets browsers on other domains call your API, so configure it in API Gateway.
- Requests time out at about 30 seconds and payloads are capped at 10 MB, so design around both.
Check your understanding
Pick an answer to see the explanation.
1. Users need to upload 200 MB videos through your app. What's the best design?
2. Your browser app gets a CORS error calling your API. Where do you fix it?