Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 688
user1249170 Avatar asked Feb 24 '14 04:02

user1249170


People also ask

How many EC2 instances can you have in an Auto Scaling group?

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.

How many EC2 instances we can create in AWS?

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.

What is the maximum number of Auto Scaling groups that AWS will allow you to create?

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.

What is the maximum number of parameters that you can use in an AWS CloudFormation template?

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.


1 Answers

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()
like image 170
Ben Whaley Avatar answered Nov 15 '22 07:11

Ben Whaley