I want to launch more than one Ec2 instances using aws cloudformation template without using AutoScaling. Please let me know how can I launch?
There are several ways to launch multiple instances using CloudFormation without having Autoscaling Group in place.
Following template has 2 resource which will launch 2 EC2 instance. You can add more resources as per requirement.
server1:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref Server1InstanceType
KeyName: !Ref ServerKeypair
ImageId: !Ref ServerImageId
SecurityGroupIds:
- !Ref ServerSG
SubnetId: !Ref PrivateWeb1b
Tags:
- Key: Name
Value: server1
server2:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref Server2InstanceType
KeyName: !Ref ServerKeypair
ImageId: !Ref ServerImageId
SecurityGroupIds:
- !Ref ServerSG
SubnetId: !Ref PrivateWeb1b
Tags:
- Key: Name
Value: server2
Following template has 1 resource which will launch 1 EC2 instance. As per 2nd method, you can create multiple Cloudformation stacks using same template to get multiple EC2 instances.
server1:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref Server1InstanceType
KeyName: !Ref ServerKeypair
ImageId: !Ref WebserverImageId
SecurityGroupIds:
- !Ref WebserverSG
SubnetId: !Ref PrivateWeb1b
Tags:
- Key: Name
Value: server1
Try using Type: AWS::EC2::EC2Fleet
You can specifies a configuration information to launch a fleet--or group--of instances. An EC2 Fleet can launch multiple instance types across multiple Availability Zones, using the On-Demand Instance, Reserved Instance, and Spot Instance purchasing models together. Using EC2 Fleet, you can define separate On-Demand and Spot capacity targets, specify the instance types that work best for your applications, and specify how Amazon EC2 should distribute your fleet capacity within each purchasing model.
**YAML**
Type: AWS::EC2::EC2Fleet
Properties:
ExcessCapacityTerminationPolicy: String
LaunchTemplateConfigs:
- FleetLaunchTemplateConfigRequest
OnDemandOptions:
OnDemandOptionsRequest
ReplaceUnhealthyInstances: Boolean
SpotOptions:
SpotOptionsRequest
TagSpecifications:
- TagSpecification
TargetCapacitySpecification:
TargetCapacitySpecificationRequest
TerminateInstancesWithExpiration: Boolean
Type: String
ValidFrom: String
ValidUntil: String
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-ec2fleet.html
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