2017-02-28 18 views
2

を使用して/customers/{customerId}というメソッドを公開しているAPIGatewayを使用しています。このメソッドは、ラムダを使用する代わりにdynamodbサービスを呼び出し、HTTP 200に空のオブジェクトを返します。CloudFormationを使用してAPIGatewayのステージ環境(キャッシング)を設定する

今、私はprodステージのキャッシングを設定します。私はAWS APIGateway Web UIを使用して作成した既存のAPIを持っており、プロダクトステージを作成しました。私はCFのそれらのプロパティを複製したい。 AVAILABLE

キャッシュ容量:0.5ギガバイト

キャッシュの生存時間(TTL):300

ここで私は私の古いAPI

キャッシュ設定

キャッシュのステータスを持っているものです

ごとのキーキャッシュの無効化

許可要求:チェック 不正な要求の処理:キャッシュ制御ヘッダーを無視します。

デフォルトメソッドスロットリングが

スロットリングを有効に応答ヘッダーで警告を追加:確認

レート:1000

バースト:200

私は最初の部分を設定してみました(キャッシュ設定)をしていましたが、私が期待していたようにプロダクトステージの設定は望ましくありませんでした。 CloudFormationを使用して上記の出力を達成するにはどうすればよいですか?あなたが"CacheClusterEnabled": trueを設定する必要があり、各段階、すなわちのプロパティで

{ 
    "AWSTemplateFormatVersion": "2010-09-09", 
    "Parameters":{ 
     "EnvType": { 
      "Type": "String", 
      "Default": "test", 
      "AllowedValues": ["test", "prod"], 
      "Description": "Select what stage need to be created" 
     } 
    }, 
    "Conditions":{ 
     "CreateProdStage" : {"Fn::Equals": [{"Ref":"EnvType"}, "prod"]}, 
     "CreateTestStage" : {"Fn::Equals": [{"Ref":"EnvType"}, "test"]} 
    }, 
    "Resources": { 
     "MyAPI": { 
      ... 
     }, 
     "MyAPIResource": { 
      ... 
     }, 
     "GetMethod":{ 
      ... 
     }, 
     "ApiDeployment":{ 
      "Type":"AWS::ApiGateway::Deployment", 
      "Properties":{ 
       "RestApiId":{"Ref":"MyAPI"} 
      }, 
      "DependsOn":["GetMethod"] 
     }, 
     "TestStage" : { 
      "Type" : "AWS::ApiGateway::Stage", 
      "Condition":"CreateTestStage", 
      "Properties" : { 
       "DeploymentId" : {"Ref":"ApiDeployment"}, 
       "Description" : "Test Stage", 
       "RestApiId" : {"Ref":"MyAPI"}, 
       "StageName" : "test" 
      } 
     }, 
     "ProdStage" : { 
      "Type" : "AWS::ApiGateway::Stage", 
      "Condition":"CreateProdStage", 
      "Properties" : { 
       "DeploymentId" : {"Ref":"ApiDeployment"}, 
       "Description" : "Prod Stage", 
       "RestApiId" : {"Ref":"MyAPI"}, 
       "StageName" : "prod", 
       "MethodSettings":[{ 
        "CachingEnabled":true, 
        "HttpMethod":"*", 
        "ResourcePath":"/*", 
        "CacheTtlInSeconds":300, 
        "ThrottlingBurstLimit" : 2000, 
        "ThrottlingRateLimit" : 1000 

       }] 
      } 
     } 

    } 
} 
+0

CloudFormationベースのAPIで正確に何が違っていたかを詳しく説明できますか? –

+0

結果スタックには 'Cache Status'が' Checked'、 'CacheCapacity'と' Cache time-to-live'が設定されていません。また、 'Per-Keyキャッシュの無効化 'を設定する方法がわかりません –

+0

(メソッド設定に加えて)ステージ定義内にCacheCluster定義がないようです。キーごとの無効化に関しては、私は雲の中でそのオプションがないようです。 –

答えて

0

: API Gatewayのステージ(CacheClusterEnabled): http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-cacheclusterenabled

APIゲートウェイMethodSettingここ

"TestStage" : { 
     "Type" : "AWS::ApiGateway::Stage", 
     "Condition":"CreateTestStage", 
     "Properties" : { 
      "DeploymentId" : {"Ref":"ApiDeployment"}, 
      "Description" : "Test Stage", 
      "RestApiId" : {"Ref":"MyAPI"}, 
      "StageName" : "test", 
      "CacheClusterEnabled": "true" 
     } 
    }, 

はドキュメントです(最初にキャッシングをステージで有効にする必要があります): http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-stage-methodsetting.html#cfn-apigateway-stage-methodsetting-cachingenabled

関連する問題