Comments (2)
Hi @truongleeuet,
Thanks for your question. I'm not sure you can cache requests based on the result of the authorizer. I haven't encountered anything about how one might do that. Some quick tests also show that API Gateway doesn't accept mapping expressions like method.request.requestContext.authorizer.roles
.
However, if your authorization is based on the value of a header, you can cache based on that value. For example, if your app sends a header like Authorization: Bearer <token>
, then you can configure caching like this:
mySecureLambda:
handler: path-to-handler/handler.handle
events:
- http:
path: /the-path
method: get
caching:
enabled: true
ttlInSeconds: 3600 # caches response of lambda for 1 hour
cacheKeyParameters:
- name: request.header.Authorization
That means that each request should be cached based on the value of the Authorization
header. If the user's role changes, you also have the option of invalidating the cache when that happens, which would mean sending a request that contains the Cache-Control: max-age=0
header along with any other cache key parameters you have configured, so API Gateway knows which key to invalidate.
Hope this helps.
from serverless-api-gateway-caching.
Closing the issue, please reopen if there are any updates.
from serverless-api-gateway-caching.
Related Issues (20)
- client certificate as cacheKeyParameters HOT 7
- Upgrade from 1.7.5 to 1.8.0 breaking API Gateway endpoint HOT 6
- Internal Server Error when setting cache key parameter request.header.Authorization HOT 2
- support for httpApi HOT 1
- Support API Gateway V2 HOT 1
- Support on cache by body on POST request HOT 6
- Serverless Offline error HOT 4
- Caching stops working as soon as I set cacheKeyParameters HOT 1
- Is there a way to invalidate all caches for a specific key? HOT 2
- Invalid logging level specified: null on v1.10.0 HOT 3
- Is it possible to ignore non 200 responses? HOT 1
- Getting a bunch of APIs with "Inherit from stage" unexpectedly HOT 4
- TTL configs not applied by Api Gateway HOT 1
- /proxy - cache miss on every request - NestJs HOT 1
- Support Chinese characters in cacheKeyParameters HOT 4
- New serverless release not compliant with pulgin HOT 2
- cacheKeyParameters are always required as of 1.10.3
- Unable to set cache key from the request context HOT 1
- API gateway cacheKeyParameters error HOT 2
- headers caching for multi-tenant HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-api-gateway-caching.