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!

已提問 9 個月前檢視次數 1129 次
2 個答案
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
已回答 9 個月前
profile pictureAWS
專家
kentrad
已審閱 9 個月前
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
專家
Kallu
已回答 9 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南