我想使用CloudFormation设置APIGateway。我有模板准备好的默认阶段,但我想根据输入参数创建阶段test
或prod
(将在CF UI中创建堆栈时输入)。
如果输入参数为prod
我想创建具有不同burst
,caching
和其他属性的舞台。
如果输入参数是test
,我想保持一切默认。
我知道如何接受输入参数并仅提供test
&下拉列表中的prod
。但是我如何在CF模板中阻止if
/ else
来自定义我的阶段?
答案 0 :(得分:0)
在CloudFormation中,您可以使用Conditions执行此操作。这是一个模板摘要,仅当 String url = "http://34.198.239.23:3000/transactions";
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
// add header
post.setHeader("User-Agent", "Mozilla/5.0");
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("secret_key", "afec6d477b7f4d91e177b707a4c58bf55b921926"));
urlParameters.add(new BasicNameValuePair("public_key", "c0b7372d96633b6414a7e7b7a53c996d3a63acfb"));
urlParameters.add(new BasicNameValuePair("product_name", "amagati"));
urlParameters.add(new BasicNameValuePair("product_unitid", "id"));
urlParameters.add(new BasicNameValuePair("product_type", "food"));
urlParameters.add(new BasicNameValuePair("error_url","vugapay.com/terms"));
urlParameters.add(new BasicNameValuePair("success_url","vugapay.com"));
urlParameters.add(new BasicNameValuePair("amount","5000"));
urlParameters.add(new BasicNameValuePair("extra_field","hello"));
urlParameters.add(new BasicNameValuePair("currency","usd"));
post.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse response = client.execute(post);
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + post.getEntity());
System.out.println("Response Code : " +
response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
// i tried to use this to view this so that it can appear in the browser
PrintWriter printwriter=response.getAllHeaders();
printwriter.print(result.toString());
System.out.println(result.toString());
System.out.println("Done!");
}
设置为CacheClusterEnabled
时才会将true
设置为ThrottlingBurstLimit
而999
设置为EnvType
:< / p>
prod
请注意,AWS::NoValue
在Fn::If
函数中使用resolve时会阻止设置该属性,因此当Parameters:
EnvType:
Description: Environment type.
Default: test
Type: String
AllowedValues:
- prod
- test
ConstraintDescription: must specify prod or test.
Conditions:
ProdEnv: !Equals [ !Ref EnvType, prod ]
Resources:
Stage:
Type: AWS::ApiGateway::Stage
Properties:
CacheClusterEnabled: !If [ProdEnv, true, !Ref "AWS::NoValue"]
MethodSettings:
-
ResourcePath: "/"
HttpMethod: "GET"
ThrottlingBurstLimit: !If [ProdEnv, 999, !Ref "AWS::NoValue"]
# ...
不是EnvType
时,将使用默认值。< / p>