use*_*170 6 amazon-web-services aws-cloudformation
假设我想为每个InstanceType创建一个EC2实例,否则它们是相同的.
所以我会像这样创建一个映射:
Run Code Online (Sandbox Code Playgroud)"Mappings" : { "MyAWSInstanceTypes" : [ "t1.micro", "m1.small", "m1.medium", "m1.large", "m1.xlarge", "m3.xlarge", "m3.2xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge", "cc2.8xlarge", "cg1.4xlarge", "hi1.4xlarge", "hs1.8xlarge" ],
后来我想拥有
Run Code Online (Sandbox Code Playgroud)"Resources" : { "MyEc2Instances" : { "Type" : "AWS::EC2::Instance",
我会神奇地获取根据映射创建的所有实例类型.
没有AutoScaling可以吗?
听起来你想循环遍历每个实例类型,创建其中一个.这在CloudFormation模板中是不可能的.
您可以以编程方式生成模板.在tropospherePython库提供了一个很好的抽象来生成模板.例如:
import json
from troposphere import Template, ec2
types = [
"t1.micro",
"m1.small",
"m1.medium",
"m1.large",
"m1.xlarge",
"m3.xlarge",
"m3.2xlarge",
"m2.xlarge",
"m2.2xlarge",
"m2.4xlarge",
"c1.medium",
"c1.xlarge",
"cc1.4xlarge",
"cc2.8xlarge",
"cg1.4xlarge",
"hi1.4xlarge",
"hs1.8xlarge"]
ami = "ami-12345678"
t = Template()
for type in types:
t.add_resource(ec2.Instance(
type.replace('.', ''), #resource names must be alphanumeric
ImageId=ami,
InstanceType=type,
))
print t.to_json()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10835 次 |
| 最近记录: |