Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Amazon EC2 Cookbook

You're reading from   Amazon EC2 Cookbook Over 40 hands-on recipes to develop and deploy real-world applications using Amazon EC2

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher Packt
ISBN-13 9781785280047
Length 194 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Selecting and Configuring Amazon EC2 Instances FREE CHAPTER 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

Selecting the right storage for your EC2 instance

Instance storage consists of disks that are physically attached to the host computer. Data on these disks is lost once the instance restarts. For persistence across restarts, we need to use EBS volumes.

EBS volumes are automatically replicated within its availability zone to protect against component failures.

AWS EBS volumes are persisted independently from your EC2 instances. These are connected through Network Attached Storage (NAS). If you lose the EC2 instance, then the data stored on EBS will still be available to a newly provisioned EC2 instance. You can attach as many EBS volumes as you want. However, an EBS volume can only be attached to one EC2 instance at a time. You can detach EBS volume from one EC2 instance, and then attach to a different EC2 instance. An I/O request of up to 256 Kilobytes is counted as a single I/O operation (IOP).

If we use standard EBS volumes as the boot device volume, then the boot process of a Windows or Linux machine is fast. We can have storage up to 16 TB and 10,000 IOPS per volume. General purpose SSD is best for boot device volumes, and small and medium sized databases. These SSD volumes can deliver a maximum throughput of 160 Mbps when attached to EBS-optimized instances.

Provisioned IOPS (SSD) volumes deliver within 10% of the IOPS performance 99.9% of the time over a given year. If we have a 200 GB volume with 1,000 IOPS, then 99.9% of the time, actual I/O on this volume will be at 900 IOPS or higher. Many database workloads need provisioned IOPS for consistent performance. We can configure storage up to 16 TB and 20,000 IOPS per volume. Provisioned IOPS volumes can deliver 320 Mbps when attached to EBS-optimized instances.

Magnetic disks are a lower cost option for EBS volumes. If data read frequency is low then this type of EBS volume is a good option.

Note

If you want more IOPS than what single EBS volume provides, configure the RAID array on multiple EBS volumes.

Encryption is also possible while using the EBS volumes. Encryption is done for data at rest, data in transit, and disk I/O. Using encrypted EBS volumes have a minor effect on I/O latency, but the performance remains the same. To encrypt EBS volume, you just need to select the Encrypt this volume checkbox when creating EBS volume from AWS console. In this recipe, we list the commands for creating an EBS volume, and then attaching it to an EC2 instance.

How to do it…

Run the following command to list the availability zones in a selected region. If the command is run in the ap-southeast-1 region, you get the list of availability zones in the Singapore region.

$ aws ec2 describe-availability-zones

Creating an EBS volume

Run the following command to create an Amazon EBS volume that can be attached to an instance in the same availability zone. Record the volume ID for further usage.

$ aws ec2 create-volume 
--availability-zone [AvailabilityZone] 
--volume-type [VolumeType]
--iops [IOPS]
--size [Size]

The parameters used in this command are described as follows:

  • [AvailabilityZone]: This specifies the availability zone in which to create the volume. Use the describe-availability-zones command to list the availability zones.
  • [VolumeType]: This gives the volume type. This can be gp2 for General Purpose (SSD) volumes, io1 for Provisioned IOPS (SSD) volumes, or standard for Magnetic volumes.
  • [IOPS]: This is only valid for Provisioned IOPS (SSD) volumes. This parameter specifies the number of IOPS to provision for the volume.
  • [Size]: This one gives the size of the volume, in GiBs.

Use the following command to create a 90 GiB Provisioned IOPS (SSD) volume with 1000 Provisioned IOPS in availability zone ap-southeast-1b:

$ aws ec2 create-volume 
--availability-zone ap-southeast-1b 
--volume-type io1 
--iops 1000 
--size 90

Attaching the volume

Run the following command to attach an EBS volumes to an EC2 instance. You will need to provide the EC2 instance ID, EBS volume ID, and the device name.

$ aws ec2 attach-volume 
--volume-id [VolumeId]
--instance-id [InstanceId]
--device [Device]

The parameters used in this command are described as follows:

  • [VolumeId]: This provides the volume ID
  • [InstanceId]: This parameter gives an EC2 instance ID
  • [Device]: This one is used to mention the device name to expose to the instance (for example, /dev/sdh or xvdh)

Run the following command to attach the EBS volume to an EC2 instance as /dev/sdf:

$ aws ec2 attach-volume 
--volume-id vol-64e54f6a 
--instance-id i-2e7dace3 
--device /dev/sdf
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 $19.99/month. Cancel anytime