In AWS CloudFormation is it possible to create a number of EC2 instances with the values from Mappings without AutoScaling group?

amazon-web-services, aws-cloudformation

Solution

No it is not possible, there is no iteration you can specify in a template. You can, however, create an instance resource for each instance type. It's a matter of copy and paste. To make it easy to tell CloudFormation which instances to run on stack creation, you can specify functions and conditions in a template. For example, you could create a parameter or parameters that indicate which instance types to start, and use conditions to start only the ones you specify.

Problem

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?

Original source