Let's say I want to create EC2 instances one per each InstanceType and otherwise they are the same.
So I would create a Mapping like this:
"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" ],
and later on I would like to have
"Resources" : { "MyEc2Instances" : { "Type" : "AWS::EC2::Instance",
where I would magically get all my instance types created as per mapping.
Is that possible without AutoScaling?
If you specify scaling policies, then Amazon EC2 Auto Scaling can launch or terminate instances as demand on your application increases or decreases. For example, the following Auto Scaling group has a minimum size of one instance, a desired capacity of two instances, and a maximum size of four instances.
Q: How many instances can I run in Amazon EC2? You are limited to running On-Demand Instances per your vCPU-based On-Demand Instance limit, purchasing 20 Reserved Instances, and requesting Spot Instances per your dynamic Spot limit per region.
Customers can now create up to 500 Auto Scaling Groups per account, an increase from 200. The limit increase enables customers to provision, manage, and scale EC2 instances for more applications per account.
You can have a maximum of 200 parameters in an AWS CloudFormation template. Each parameter must be given a logical name (also called logical ID), which must be alphanumeric and unique among all logical names within the template. Each parameter must be assigned a parameter type that is supported by AWS CloudFormation.
It sounds like you want to loop through each instance type, creating one of each. This is not possible in a CloudFormation template.
You could programmatically generate a template. The troposphere
Python library provides a nice abstraction to generate templates. For example:
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With