API Gatewayのキャッシュ機能[解決済み]
キャッシュ機能
https://docs.aws.amazon.com/ja_jp/apigateway/latest/developerguide/api-gateway-caching.htmldocs.aws.amazon.com
ヘッダやクエリパラメータは個別にキャッシュキーに使う設定をすればいいらしい。 ということでCloudFormationのテンプレートを書いてみたのだが、、、
書いたテンプレート(抜粋)
Resources: MyApi: Type: AWS::ApiGateway::RestApi Properties: Name: MyApi MyApiResource: Type: AWS::ApiGateway::Resource Properties: RestApiId: Ref: MyApi ParentId: Fn::GetAtt: - MyApi - RootResourceId PathPart: hoge MyApiMethod: Type: AWS::ApiGateway::Method Properties: HttpMethod: GET ResourceId: Ref: MyApiResource RestApiId: Ref: MyApi AuthorizationType: NONE RequestParameters: method.request.querystring.foo: true method.request.querystring.bar: false Integration: CacheKeyParameters: - method.request.querystring.foo - method.request.querystring.bar MyApiDeployment: Type: AWS::ApiGateway::Deployment Properties: RestApiId: Ref: MyApi StageName: fuga StageDescription: CacheClusterEnabled: true CacheClusterSize: 0.5 CachingEnabled: true MethodSettings: - HttpMethod: GET ResourcePath: /hoge CachingEnabled: true
普通のリクエストだとキャッシュされるが、、、
問題のリクエスト
GET /hoge?foo=one&bar=two&foo=three
GET /hoge?foo=one&bar=two&foo=four
1.と2.のレスポンスは同じものが返ってきてしまう。。。 どうやら同名のパラメータが複数あると、どういう基準でキャッシュキーを作っているのだろう🤔 (今回はキャッシュを使うことはMUSTでは無かったので、これ以上深入りしなかった。。。)
同名複数パラメータを受け入れられるようになったのはそんなに前では無いから、このあたりもこれから対応されるのだろうか?
解決(2019/12/21追記)
この問題、CloudFormationのstackをupdateしてもAPIGatewayのstageにdeployされるわけでは無かった、というだけでした、、、
CloudFormationだけでdeployするやり方が分からなかったので、以下のコマンドでとりあえず解決。
$ aws apigateway create-deployment --rest-api-id hoge --stage-name fuga --description "deployment"