Create copy of EC2 instance and launch as new instances - amazon-web-services

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.

Related

Does creating an AMI on AWS require the reboot of the original machine?

When creating an AMI image from an existing EC2 instance, does it require the restart of the existing instance?
I make a copy of the instance, and subsequently the server went down because it turned off a process monitor which led to downtime, but I can't remember if it was because I rebooted the system (I can't remember if I rebooted it), or if it was because I made a copy of the image.
There's option to enable No reboot during create AMI
When creating an AMI image from an existing EC2 instance, does it require the restart of the existing instance
to answer this yes, when ami is being created aws the instance for ensuring data integrity.
doc says this "Amazon EC2 powers down the instance before creating the AMI to ensure that everything on the instance is stopped and in a consistent state during the creation process."
you can override this behaviour by enabling no reboot while creating ami.
No reboot – This option is not selected by default. Amazon EC2 shuts down the instance, takes snapshots of any attached volumes, creates and registers the AMI, and then reboots the instance. Select No reboot to avoid having your instance shut down.
refer 6 point of this https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/creating-an-ami-ebs.html.
also whenever you are unsure about anything just follow the docs of that service, it will be define in one way or the another.

EC2 - New Instance Vs (remount) EBS-backed instance

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.

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.

unable to access server after changing permission AWS

I accidentally changed the permission of home folder via SSH, now I am unable to access the files, please suggest me what to do, don't want to lose the files.
If you've locked yourself out of an instance, you have two options to recover (assuming the data is on EBS - if it's on instance storage, you're out of luck)
Option #1 is to:
create a snapshot of the EBS volume
then, create a volume from the snapshot
launch a new EC2 instance using a key you have access to
associate the volume from step 2 with the instance in step 3
log into the instance and mount the volume
You now have access to the data
Option #2 is to fix the existing instance
Stop the bad instance
Disassociate the EBS volume from the stopped instance
launch a new EC2 instance using a key you have access to
Associate the volume with the instance you just created
log into the instance and mount the volume
Fix the permissions
Reverse the process: unmount, disassociate from new instance, re-associate with old instance, boot the old instance and you should be good.

Swap space using instance-store in HVM EBS AMI in AWS

On AWS EC2, if we launch and AMI with instance-store, we can attach EBS volume for persisent store. Is the vice-versa possible.
ie.,
Can we add instance-store volume when launching a EBS HVM AMI, the reason behind this is to use it as a swap.
I can't see the option to add Instance store on Storage Configuration, while launching a EBS backed instance.
Please let me know, if there is a method to achieve root volume as EBS and swap volume as instance-store.
many thanks,
Shan
If you are launching an instance class that includes instance store (ephemeral) disks, those should be accessible from Storage Configuration, as in this example, where the instance class provides two ephemeral disks.
See Instance Storage in the EC2 documentation to confirm whether the instance class you're launching includes instance store volumes. Some classes do not, and where that is the case, you can only select EBS as the Volume Type.
If you're launching from an AMI that already contains references to the ephemeral disks, you should see something like this screen shot. If it doesn't include references to the instance store volumes, you can use Add New Volume to include the desired instance store volumes with the new instance. Their sizes are fixed by the specs of the instance class, which is why Size says N/A. Since they are provided at no charge, you should always attach them at launch, even if you have no plan for them, because they can't be added after launching.
AMIs can't be edited, so if you want these included automatically on future launches, you'll need to build a new AMI, which you'll probably also want to be configured (within the OS boot sequence) to create and mount the desired swap space.