EC2 - New Instance Vs (remount) EBS-backed instance - amazon-web-services

I have a an Ubuntu-14.04 EC2 instance running with EBS volume
I regularly take snapshot
I launched a new instance Ubuntu-16.04.
I detach the root volume
I created a EBS volume from snapshot above
I re-attached the volume.
I see all the data and my servers seem to work on the new instance. For eg. mongo, app servers etc.
My question is (other than app data):
What are the differences between the new instance and the instance launched via an existing EBS?
Is the existing-EBS-launched instance supposed to work like the old instance without any changes, out-of-the-box?

What are the differences between the new instance and the instance launched via an existing EBS?
Answer- first of all, understand what EBS is, in a simple language, it is a block storage volume for use with Amazon EC2 Instance.
So Whenever you launch a new Instance via an existing EBS, all the stuff/ any manual changes on the disk which you have done previously will be automatically reflected in your new Instance, as you are using the same disk (Block Storage). It's just when you want any kind of modification like wants to change the key pair at that time we detach the volume, do the modifications and again attach the volume (disk).
Is the existing-EBS-launched instance supposed to work like the old instance without any changes, out-of-the-box?
Answer- yes Existing EBS launched instance work as the old instance, its just what kind of modification you have provided to the new instance. Suppose while launching you have changed the Type of instance, key pair, attach different security group. So all these changes will be reflected and all the manual operations done on Disk will remains same.

Related

AWS Auto scaling terminating instance & creating 2nd instance with new root volume & IP. what is the use of auto scaling here?

AWS Auto scaling terminating instance & creating 2nd instance with new root volume,1st instance root volume available! what is the use of auto scaling here? It just created empty instance, IP changed,rpm's,services installed not replicated to 2nd instance.
If I manually deatach attach root volume of old instance to new instance and restore services manually then what is the use of Auto Scale?
Any way to handle this?
Amazon EC2 Auto Scaling will always scale-out by launching a new EC2 instance (including its own Amazon EBS boot volume) and will scale-in by terminating an EC2 instance. By default, EBS volumes on a terminated instance will be deleted by this can be overridden to keep the volume (but it won't be used when Auto Scaling launches a new instance).
To pre-load software onto an Amazon EC2 instance that is launched by Auto Scaling, there are two choices:
Create a fully-configured AMI containing all desired software and configurations. When Auto Scaling launches a new instance, it will create a boot volume (and additional volumes if desired) and will automatically load the disk contents from the AMI (Amazon Machine Image). Thus, each instance will boot with a fully-configured disk. It is your responsibility to create the AMI and maintain it with the latest version of the software you want to use. Also, please note that each new instance contains exactly what was saved on the AMI -- any changes to a disk attached to an instance is not reflected on any other instances because they are separate disk volumes.
Use a startup (User Data) script to configure the instance after it boots. This script can download and install software, set configurations and do anything you wish to script! The downside is that it takes a little longer for the instance to be ready because it needs to perform these startup tasks. The benefit of this method is that the software can be updated simply by starting a new volume — the script could automatically download the latest version of the software (whereas an AMI always contains the same contents unless a new AMI is created). This is a great way to upgrade systems — just throw away an old instance and start a new instance!
It is also possible to combine these two methods, such as having a mostly-configured AMI (eg with desired frameworks and security configurations) and then use a startup User Data script to finish the setup by installing the application.

Create copy of EC2 instance and launch as new instances

I setup one mail server in one EC2 instances. I want to copy the whole instance and launch as another new instance.
I'm very confused about snapshot and AMI, so please suggest how to do it.
When talking about creating a copy or clone of an instance, there's two aspects to consider:
The configuration of the instance itself, such as Instance Type, Security Group, IAM Role and network subnet
The contents of the disk volume(s)
To launch an instance with the same instance configuration, use the Launch More Like This option in the actions menu, which can launch a new instance with the same configuration. This will also select the original AMI used to launch the initial instance -- please note that this means it will have the same disk as sued when launching the initial instance, but will not have a copy of all data stored/changed on the initial instance since it was first started.
If you wish to make a perfect copy of the instance, including the contents of the disk volume(s), then create an AMI (see documentation for Linux and Windows). This will make a copy of the disk volume(s) so that any instance launched from the AMI will have the same data on disk. Then, launch a new instance from that AMI.

Is it possible to modify an existing AMI to change delete on termination settings on the EBS volumes?

I have several AMIs that developers use to spin up instances. These AMI do not have "delete on termination" set on all their EBS volumes. At times terminating instances launched using these AMIs has the unintended consequence of leaving behind orphan EBS volumes. Unfortunately, "blessing" a new AMI for general use is quite an ordeal. Is it possible to edit an existing AMI to turn on "delete on termination" or is the only way forward to create a new AMI with the proper settings?
It is not possible to modify the "Delete on termination" value on an existing AMI.
So you have 2 choices:
Launch an EC2 instance from your AMI and produce a new AMI with the appropriate "Delete on Terminate" value, or
Modify the value when you launch the new EC2 instance.
Once the instance is running you can call modifyAttribute (modify-instance-attribute in the CLI) on the attribute blockDeviceMapping.
aws ec2 modify-instance-attribute --instance-id i-a3ef245 --block-device-mappings "[{\"DeviceName\": \"/dev/sda\",\"Ebs\":{\"DeleteOnTermination\":false}}]"
You can see an example here: http://www.petewilcock.com/how-to-modify-deletion-on-termination-flag-for-ebs-volume-on-running-ec2-instance/
There is no such features.
In addition, I think you misundestand the purpose of AWS web console EC2 EBS Volumes vs snapshot.
When you launch an instances, a EBS Volume is assign to the instance(if it is a EBS base instance like t2., c3.) , once you terminate it, that assoicated volume will be deleted.
Unless you create a EBS volumes that attach to a instances, that is another story. An attached volumes will stay even the instance it attached to is deleted, this is intended design as EBS volumes is network storage anyway, it should allow you to detach/attach to different instances dynamically.
On the other hand, your user may create snapshot(s) for their instances, which store under the Snapshot portion. This is part that will stay, even you terminate the original instance. Once you deleted the original instance, the volume it point do will be "orphaned".
It is a good practice to create a snapshot for instance as backup, but it will go wilds if you don't have a standard policy to handle it. No automation can help a process nature issues.
You MUST enforce a policy and standard for your developer to follow as well, e.g. backup cycle, tag for snapshot, etc.

Doubts about recovering a .pem of an EC2 in AWS

We are working with an EC2 instance in Amazon Web Services but we have lost our .pem.
In order to create a new one, we are following this guidance:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#replacing-lost-key-pair
However, we are a bit worried because of this warning:
When you stop an instance, the data on any instance store volumes is
erased. Therefore, if you have any data on instance store volumes that
you want to keep, be sure to back it up to persistent storage.
We cannot access the instance, therefore we cannot really make a proper backup. Instead, we have make a snapshot of the volumes in Elastic Block Store.
We are wondering if this is enough and we can indeed stop the instance to proceed to the pair key recover or we need to do something else in order not to lose any data.
It depends on the type of instance.
If it's EBS backed you are probably safe to proceed as the volume will be reattached.
If it's instance store backed and you lost access to it you basically have lost what's on that machine.
By the sounds of it it's EBS backed. If it's instance store backed and you later created and attached an EBS volume and used that, you're going to be able to restore/reattach that volume just fine - but it's going to be to another machine.
Depending on how many instances we are talking about you should also be able to take an AMI Image of the running instance which will take snapshot of the EBS but also the exact state of the instance.
However if the instance's root device type is using a EBS backed store all the data should be safe so saving a snapshot and relaunching a new instance with the snapshot should have the data.
Good luck.

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