Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Amazon EC2 Cookbook

You're reading from  Amazon EC2 Cookbook

Product type Book
Published in Nov 2015
Publisher Packt
ISBN-13 9781785280047
Pages 194 pages
Edition 1st Edition
Languages

Table of Contents (15) Chapters

Amazon EC2 Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
1. Selecting and Configuring Amazon EC2 Instances 2. Configuring and Securing a Virtual Private Cloud 3. Managing AWS Resources Using AWS CloudFormation 4. Securing Access to Amazon EC2 Instances 5. Monitoring Amazon EC2 Instances 6. Using AWS Data Services 7. Accessing Other AWS Services 8. Deploying AWS Applications Index

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
You have been reading a chapter from
Amazon EC2 Cookbook
Published in: Nov 2015 Publisher: Packt ISBN-13: 9781785280047
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}