Showing posts with label ebs volumes. Show all posts
Showing posts with label ebs volumes. Show all posts

Apr 8, 2018

AWS EBS

EBS Encryption support
EBS Encryption is supported in all EBS volume types
But not all EC2 instances support encryption

EBS Volume/Snapshot - Encryption keys
KMS  - AWS Key management service
CMKs - Customer master keys
When you encrypt first EBS volume, AWS KMS creates default CMS key
After that, each newly encrypted volume is encrypted with a unique/separate AES256 bits encryption key

Sharing EBS Snapshots
Only account owner can create volume from snapshots
Encrypted snapshots cannot be shared, only un-encrypted are meant to be shared
But an Encrypted snapshot can be shared to a selected AWS account id, by making them private (with cross-account permissions)
Account A - with Key 1, has shared encrypted snapshot with Account B, Account B owner needs to create a copy of snapshot with his own key(Key 2) & create volumes 
AWS will not allow you to share snapshots encrypted using default CMK key ****
Snapshots are stored in S3 (unknown location to us)
S3 SSE protects snapshot data in transit

Copy Snapshots
Copy snapshot to another to encrypt or to another region
user defined tags are NOT copied from original
5 copy requests per account in parallel

Instance Backed AMI vs EBS Backed AMI
When you create EC2 AMI, AWS automatically EBS volume(s) & Intance root volume snapshots are created
When snapshots attached to AMI, you cannot delete snapshots, you need to de-register AMI & delete snapshots
1) Instance Backed AMI
  You need to register AMI (in Amazon market place)
You need to specify S3 bucket for storing snapshots
2) EBS Backed AMI
Registration of AMI happens automatically
You don't need to specify S3 bucket
When creating EMI, stop instance to ensure data consistancy and integrity
EBS Snapshots are point in time
How to ensure EBS data consistancy (stop EC2 instance is best)
1) Pause I/O operations on EBS from EC2
2) Unmount EBS volumes, create snapshot & mount again

RAID in EBS (Redundant array of independent disks)
Increase I/O performance/throughput of EC2
using EBS optimized EC2 instances
use RAID array of EBS volumes
RAID array is collection of multiple EBS volumes
Make sure EC2 max bandwidth >= Total I/O of EBS volume (or RAID)
RAID is not meant for root/boot volumes of EC2
RAID 0 - stripping
Fastest of all RAID types
Distributing data to be written over array of disks in parallel (without redundancy) - faster
If data fails in one volume, whole array of EBS volumes gets corrupted
RAID 1 -  Mirroring
Cares about redundancy but not faster
Not able achieve I/O performance/throughput
RAID 10 - It has benefits of both RAID0 & RAID1


EBS Practice scenarios
  • non-encrypt to encrypt 
  • copy ebs to another AZ
  • make ebs volume public/private
  • Encryption types
  • customer specific encryption
  • play in CMK & other encrypt patterns - customer managed keys
  • copy snapshot to another region
  • copy snapshot to another AWS account 
  • attach to EC2 & mount
  • increase/decrease EBS volume size
  • Root volume encrypt (work around)
  • Do I need to turn off EC2 while taking backup?


Apr 7, 2018

How to encrypt an existing ebs volume of an EC2 instance

How to encrypt an existing ebs volume of an EC2 instance ?
 

  • 1)
    • Take snapshot of existing ebs volume
    • copy snapshot of above to new encrypted snapshot (using encryption)
    • create volume from the encrypted snapshot (in the same us-east-1a/us-east-1b/us-east-1c availability zone as of EC2)
    • stop ec2 instance
    • detach existing unencrypted ebs volume
    • attach new encrypted ebs volume to the ec2 instance
    • start the instance again
  • 2)
    • Assume you have an non-encrypted EBS volume attached to EC2 instance
    • Create an EBS volume with encrypt option
    • Attach encrypted EBS volume to EC2 (in addition to the existing non-encrypted EBS volume)
    • Now EC2, 2 EBS volumes are under a single AZ say us-east-1a
    • 1st EBS volume mounted to /opt/ebs1 -> non-encrypted EBS volume
    • 2nd EBS volume mounted to /opt/ebs2 -> Encrypted EBS volume
    • Now copy content from non-encrypted EBS volume to Encrypted EBS volume
    • Once done, detach non-encrypted EBS volume from EC2 instance
Note:
  • EBS volumes are limited to a specific availability zone
    Snapshots are limited to a specific region
    EC2 and EBS volumes attached to the EC2 instance must be in the same AZ
    However you can copy snapshots across regions

How to make an Amazon EBS Volume Available for Use - mount

How to make an Amazon EBS Volume Available for Use
Please find the steps to mount EBS volume to Ec2 instance

  • Attach to EC2 intance
  • Login to EC2 instance
  • lsblk - gives list of volumes
    • NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    • xvda 202:0 0 8G 0 disk
    • xvda1 202:1 0 8G 0 part /
    • xvdf 202:80 0 10G 0 disk
  • sudo file -s /dev/xvdf #for new volumes (it shows as data)
    • /dev/xvdf: data
  • sudo file -s /dev/xvda1 #for existing
    • /dev/xvda1: Linux rev 1.0 ext4 filesystem data, UUID=XXXXX-XXXX-XXXXX-XXXX-XXXXXX (needs journal recovery) (extents) (large files) (huge files)
  • cd ~
  • mkdir ebsvolume
  • sudo mkfs -t ext4 /dev/xvdf
  • sudo mount /dev/xvdf ebsvolume
  • df -h
  • lsblk
    • NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    • xvda 202:0 0 8G 0 disk
    • └─xvda1 202:1 0 8G 0 part /
    • xvdf 202:80 0 10G 0 disk /root/ebsvolume

Note:

EC2 instance, EBS volumes must be in a same AZ