2017-02-27 87 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