2017-02-27 86 views
0

我有以下CF模板爲APIGateway方法設置緩存

{ 
    "Conditions":{ 
     "CreatedProdStage" : {...} 
    } 
    ... 
    "Resources":{ 
     "GetMethod": { 
      ... 
     }, 
     "ApiDeployement":{ 
      ... 
     }, 
     "ProdStage":{ 
      "Type":"AWS::ApiGateway::Stage", 
      "Condition":"CreatedProdStage", 
      "Properties": { 
       "DeploymentId":"...", 
       "RestApiId":"...", 
       "MethodSettings":[{ 
        "CachingEnabled":true, 
        "HttpMethod":{"Ref":"GetMethod"}, 
        "ResourcePath":"/" 
       }] 
      } 
     } 
    } 
} 

而且我得到錯誤

無效的方法設置路徑: /〜1/ST-GetMetho-xxxAUMMRWxxx /緩存/啓用。必須是以下其中一個: [/ deploymentId,/ description, /cacheClusterEnabled/cacheClusterSize/clientCertificateId/{resourcePath}/{httpMethod}/metrics/enabled, /{resourcePath}/{httpMethod}/logging/dataTrace, /{資源路徑}/{httpMethod}/logging/loglevel, /{resourcePath}/{httpMethod}/throttling/burstLimit/{resourcePath}/{httpMethod}/throttling/rateLimit/{resourcePath}/{httpMethod}/caching/ttlInSeconds, /{resourcePath}/{httpMethod} /緩存/啓用, /{resourcePath}/{httpMethod}/caching/dataEncrypted, /{resourcePath}/{httpMethod}/caching/requireAuthorizationForCacheControl, /{resourcePath}/caching/unauthorizedCacheControlHeaderStrategy, // /度量/使能時,/ / /記錄/ dataTrace,/ / /記錄/記錄級, // /節流/ burstLimit// /節流/ rateLimit // /緩存/ ttlInSeconds ,/ / /緩存/啓用, // /緩存/ dataEncrypted, // /緩存/ requireAuthorizationForCacheControl, // /緩存/ unauthorizedCacheControlH eaderStrategy,/ va

我錯過了什麼嗎?我想ResourcePathHttpMethod是唯一必需的屬性

回答

0

嘗試列舉HTTPMethod設置爲一個字符串,而不是一個參考:

"MethodSettings":[{ 
     "CachingEnabled":true, 
     "HttpMethod": "GET", 
     "ResourcePath":"/" 
    }] 
} 
+0

已經嘗試過,沒有工作。 –

+0

有趣 - 如果它不一樣,你能發佈錯誤嗎? –

+0

沒有錯誤。 「HttpMethod」和「ResourcePath」創建的堆棧已改變(如您所建議的那樣),但緩存尚未啓用。 –

1

您首先需要啓用與CacheClusterEnabled財產階段緩存。這將允許您設置方法的緩存方法如下:方法設置:

... 
"ProdStage":{ 
     "Type":"AWS::ApiGateway::Stage", 
     "Condition":"CreatedProdStage", 
     "Properties": { 
      "DeploymentId":"...", 
      "RestApiId":"...", 
      "CacheClusterEnabled": true 
      "MethodSettings":[{ 
       "CachingEnabled":true, 
       "HttpMethod":{"Ref":"GetMethod"}, 
       "ResourcePath":"/" 
      }] 
     } 
    } 

然後,您需要修復給定的錯誤。您的ResourcePath與錯誤輸出中列出的其中一個匹配。那些沒有在文檔中列出,所以你需要使用它有點混亂。您目前所擁有的僅爲根路徑設置。如果你想所有的路徑使用"/*"

APIGateWay :: MethodSettings(見ResourcePath)DOC: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-stage-methodsetting.html