Life cycle of EBS and EC2 of Amazon - amazon-web-services

Does the life cycle of an EBS volume is coupled with the life cycle of an EC2 (meaning terminating an EC2 will terminate EBS volume as well)?

No , terminating instance will not terminate EBS volume attached with it , thus you wont lose your DATA .

It depends on how the EBS volume was created. If it was created during the EC2 instance launch with the "Delete on Termination" flag set, it will be deleted, otherwise it will just remain as a unattached volume.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html

Related

EBS Snapshot; Restarting EC2 Instance before Snapshot complete

It is my understanding that when you create an EBS Snapshot, any data written to the volume up to the time that the snapshot was started, will be included. I.e, even if the snapshot is in the "pending" state, it is still safe to write to the EBS volume.
Is this still considered the case for taking EBS snapshots of root volumes? In the documentation, it is stated that when you create a snapshot for Amazon EBS volumes that serve as root devices, you should stop the instance before taking the snapshot.
Does this imply that we can stop the instance, begin the snapshot, and then restart the instance before the snapshot has completed? The reason I'm asking is because our snapshots are taking >15 minutes, which is timing out our Snapshot Management Lambda before it can restart the instance.
It should be safe, see https://serverfault.com/questions/548731/can-i-re-attach-my-ebs-while-a-snapshot-is-pending
You should stop the instance when creating a root volume snapshot because you can not unmount root volume beforehand, hence you would risk your snapshot would be corrupted.

Automatically attach and mount EBS volume on new EC2 instance

Scenario
I currently have an EC2 instance with a root EBS volume attached to it of 30gb and i have some files stored in that EBS
If i delete the EC2 instance and have delete on termination false then EBS persists.
Desired outcome
I want to provision a new EC2 (provisioned by auto scaling group) instance such that it uses the old EBS volume as its root volume which was detached as a result of me terminating the old instance
Note
I want to have the liberty of choosing OS of newly provisioned EC2 so creating an AMI does not work
You cannot directly launch a new Amazon EC2 instance with an existing Amazon EBS volume. Instead, you would need to:
Launch a new Amazon EC2 instance with a new root volume
Stop the instance
Detach the root volume
Attach the 'old' EBS volume
Start the instance
Storing data in root EBS volume might be a bad idea to start with.
Consider one of the following:
Mount another EBS volume to the instance to store required data only.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html
best performance, highest cost/effort, but your application doesn't
change a bit.
Create EFS and mount it to your instances. https://docs.aws.amazon.com/efs/latest/ug/mounting-fs.html -
reasonable effort, minimal if any changes to the application.
Store data in S3. Ideal from price standpoint; requires changes to the application.

Launching AWS spot instance with an old EBS volume

I do not now much about spot instances but I'm wondering whether I have to create a new EBS volume with every instance or is it possible to start an instance with a previously launched EBS volume ?
Amazon provides an option to do the same.
Delete on termination false spot instances

Are the ebs volumes used by the instances launched by an autoscaling group deleted when the instances are replaced/terminated?

I have an auto-scaling group with 2 instances.
Every time an instance is launched an EBS volume is attached to it. When it is replaced/terminated is the EBS volume deleted ?
I want to keep a tight budget on my account and I dont want to have volumes lingering and pay for them.
You can configure it both ways. If you are using the web interface to configure the launch configuration when you get to Storage you will see this:
You just need to check the "Delete on Termination" checkbox on the right, whenever an instance is terminated the EBS volume associated will be deleted as well.

What data is stored in Ephemeral Storage of Amazon EC2 instance?

I am trying to stop a Amazon EC2 instance and get the warning message
Warning: Please note that any data on the ephemeral storage of your instance will be lost when it is stopped.
My Question
What data is stored in ephemeral storage of an Amazon EC2 instance?
Basically, root volume (your entire virtual system disk) is ephemeral, but only if you choose to create AMI backed by Amazon EC2 instance store.
If you choose to create AMI backed by EBS then your root volume is backed by EBS and everything you have on your root volume will be saved between reboots.
If you are not sure what type of volume you have, look under EC2->Elastic Block Store->Volumes in your AWS console and if your AMI root volume is listed there then you are safe. Also, if you go to EC2->Instances and then look under column "Root device type" of your instance and if it says "ebs", then you don't have to worry about data on your root device.
More details here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/RootDeviceStorage.html
Anything that is not stored on an EBS volume that is mounted to the instance will be lost.
For example, if you mount your EBS volume at /mystuff, then anything not in /mystuff will be lost. If you don't mount an ebs volume and save stuff on it, then I believe everything will be lost.
You can create an AMI from your current machine state, which will contain everything in your ephemeral storage. Then, when you launch a new instance based on that AMI it will contain everything as it is now.
Update: to clarify based on comments by mattgmg1990 and glenn bech:
Note that there is a difference between "stop" and "terminate". If you "stop" an instance that is backed by EBS then the information on the root volume will still be in the same state when you "start" the machine again. According to the documentation, "By default, the root device volume and the other Amazon EBS volumes attached when you launch an Amazon EBS-backed instance are automatically deleted when the instance terminates" but you can modify that via configuration.
To be clear and answer #Dean's question: EBS-type root storage doesn't seem to be ephemeral. Data is persistent across reboots and actually it doesn't make any sense to use ebs-backed root volume which is 'ephemeral'. This wouldn't be different from image-based root volume.
For EC2 instance
Stop & Start != Reboot
so for ephemeral storage (Instance Store)
Stop cause data lost
Reboot will not
According to AWS documentation [https://aws.amazon.com/premiumsupport/knowledge-center/instance-store-vs-ebs/] instance store volumes is not persistent through instance stops, terminations, or hardware failures.
Any AMI created from instance stored disk doesn't contain data present in instance store so all instances launched by this AMI will not have data stored in instance store. Instance store can be used as cache for applications running on instance, for all persistent data you should use EBS.
ephemeral is just another name of root volume when you launch Instance from AMI backed from Amazon EC2 instance store
So Everything will be stored on ephemeral.
if you have launched your instance from AMI backed by EBS volume then your instance does not have ephemeral.
refer: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-volumes
The data in an instance store persists only during the lifetime of
its associated instance. If an instance reboots (intentionally or
unintentionally), data in the instance store persists. However,
data in the instance store is lost under any of the following
circumstances:
- The underlying disk drive fails
- The instance stops
- The instance hibernates
- The instance terminates