Grouping EC2 instances using placement groups

EC2 instances can be grouped using placement groups. For example, instances requiring low latency and high bandwidth communication can be placed in the same placement group. When instances are placed in this placement group, they have access to low latency, non-blocking 10 Gbps networking when communicating with other instances in the placement group (within a single availability zone). AWS recommends launching all the instances within the cluster placement group at the same time.

How to do it…

In order to group EC2 instances using placement groups, first we create a placement group, and then add our EC2 instances in it.

Creating a placement group

Run the following command to create placement groups. You have to provide the placement group name and the placement strategy.

$ aws ec2 create-placement-group 
--group-name [GroupName] 
--strategy [Strategy]

Here, the GroupName parameter specifies a name for the placement group and the Strategy parameter specifies the placement strategy.

Next, run the following command to create a placement group with the name WebServerGroup:

$ aws ec2 create-placement-group 
--group-name WebServerGroup 
--strategy cluster

Placing instances in the placement group

Run the following command to launch instances in a placement group. You will need to specify the placement group name along with the EC2 instance properties.

$ aws ec2 run-instances 
--image-id [ImageId] 
--count [Count]
--instance-type [InstanceType]
--key-name [KeyPairName]
--security-group-ids [SecurityGroupIds]
--subnet-id [SubnetId]
--placement [Placement]

The parameters used in this command are described as follows:

  • [ImageId]: This gives the ID of the image from which you want to create the EC2 instance
  • [Count]: This one provides the number of instances to create
  • [InstanceType]: This option gives the type of EC2 instance
  • [KeyPairName]: This parameter provides the key pair name for the authentication
  • [SecurityGroupIds]: This parameter gives one or more security group IDs
  • [SubnetId]: This option provides the ID of the subnet where you want to launch your instance
  • [Placement]: This gives the placement for the instance.

    Syntax:

    --placement AvailabilityZone=value,GroupName=value,Tenancy=value
    

Next, execute the following command to launch a c3.large EC2 instance in the WebServerGroup placement group:

$ aws ec2 run-instances 
--image-id ami-7e2c612c 
--count 1 
--instance-type c3.large 
--key-name WebServerKeyPair
--security-group-ids sg-ad70b8c8 
--subnet-id subnet-aed11acb 
--placement GroupName= WebServerGroup
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset