Instantiate multiple EC2 instances using AWS Cloud Formation Template.

1

Hi there, I have a use-case, where I want to instantiate variable number of EC2 instances depending on the input provided by the user. for ex: If user provided 3 as input then 3 Ec2 instances should be instantiated and so on.

Please guide me here, I am stuck with this for few days now.

thanks in advance!

asked 10 months ago1168 views
2 Answers
1

You can try this way, but I think there is more elegant solution:

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::LanguageExtensions

Parameters:
    InstanceList:
        Type: CommaDelimitedList

Resources:
  Fn::ForEach::Instances:
    - InstanceLogicalId
    - !Ref InstanceList
    - ${InstanceLogicalId}:
        Type: AWS::EC2::Instance
        Properties:
          ImageId: ami-0ed752ea0f62749af
          InstanceType: t2.micro

Then in a console just type the name of logical id, like:

 instance1 - will create one instance
 instance1, instance2, instance3 - will create three instances
profile picture
answered 10 months ago
profile pictureAWS
EXPERT
kentrad
reviewed 10 months ago
0

You can also do this with Count -macro. There were some issues using parameters with Count attribute but based on comments those shound have been fixed.

profile picture
EXPERT
Kallu
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions