Caching AWS使用SAM API网关的queryStringParameter PathParameter启用缓存
我想为我的无服务器函数启用API网关缓存,但很难理解在何处以及以何种方式进行缓存 我曾尝试在我的无服务器函数中设置queryStringParameters,但结果是错误的,我还尝试将它们添加到我的全局Api中,但没有成功(我也希望避免在全局Api中这样做) 还检查了API网关中的“我的资源”,并禁用了RequestParams的缓存,其中缺少QueryStringParamsCaching AWS使用SAM API网关的queryStringParameter PathParameter启用缓存,caching,aws-lambda,aws-api-gateway,aws-sam,serverless-application-model,Caching,Aws Lambda,Aws Api Gateway,Aws Sam,Serverless Application Model,我想为我的无服务器函数启用API网关缓存,但很难理解在何处以及以何种方式进行缓存 我曾尝试在我的无服务器函数中设置queryStringParameters,但结果是错误的,我还尝试将它们添加到我的全局Api中,但没有成功(我也希望避免在全局Api中这样做) 还检查了API网关中的“我的资源”,并禁用了RequestParams的缓存,其中缺少QueryStringParams 作为参考: 作为参考: 作为参考: 模板 AWSTemplateFormatVersion: '2010-0
- 作为参考:
- 作为参考:
- 作为参考:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Api:
EndpointConfiguration: REGIONAL
CacheClusterEnabled: true
CacheClusterSize: "0.5"
MethodSettings:
- CachingEnabled: true
CacheDataEncrypted: true
CacheTtlInSeconds: 60
HttpMethod: "*"
ResourcePath: "/*"
Resources:
......
GetItem:
Type: 'AWS::Serverless::Function'
Properties:
Handler: GetItem.handler
Runtime: nodejs8.10
Timeout: 20
CodeUri: "codes"
Events:
GetItem:
Type: Api
Properties:
Path: /item/{itemCode}
Method: get
......
***********************************编辑*********************************
如果发现API网关不知道参数,那么它将忽略它进行缓存
我尝试向模板添加多个methodSetting条目,CF似乎没有忽略它,但结果仍然相同。此外,如果可能的话,我不知道如何对queryStringParameters执行相同的操作
- ResourcePath: "/~1item~1/~1{itemCode}"
CachingEnabled: true
CacheDataEncrypted: true
CacheTtlInSeconds: 60
HttpMethod: "*"
***********************************编辑*********************************
我更喜欢在每个资源(也称为“AWS::Serverless::Function”)下为RequestParams和QueryParams启用缓存的方法
非常感谢您的帮助。此时,SAM框架不支持这样做。他们计划发布一个更新,在该更新中,他们在该链接上启用了更多功能: 在那之前,我唯一能想到的解决方案是在API网关前创建CloudFront发行版,这是一种资源浪费,但效果很好