Finding out AMI associated with an instance - amazon-web-services

Is there a way to find out AMI's associated with an Instance?
Like for example, I have test_instance.
I would like to find out AMI's that have been generated with this instance.
So, basically I am trying to terminate the instance and all the AMI's and volumes associated with it.

When you terminate instance, by default root volume is deleted (can be changed by DeleteOnTermination proerty) but any additional EBS volumes that you attach at launch, or any EBS volumes that you attach to an existing instance persist even after the instance terminates.
So, if you have only root volume, and DeleteOnTermination set to true, you can just terminate the instance and volume will be deleted.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html
For the AMI, if you used a public/AWS provided AMI, you cannot delete that. If you are using your own AMI, you have to deregister the AMI and delete the snapshot used to create the AMI.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/deregister-ami.html
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-deleting-snapshot.html

Related

How to restore ec2 instance. i dont have snaphot of the EC2, but the EC2 was not terminated it is up and running?

For some reason, I would like to restore my EC2 instance. But I don't have any snapshot of that instance. Also, I won't able to SSH login to Ec2 instances. What is the alternate way to change the system settings to default?
You cannot undo an instance termination or restore it without a snapshot. I suggest you enable termination protection on your EC2 instances to protect against accidental termination:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingDisableAPITermination
I found a way to roll back my instance to a restore default option by changing the root EBS Volume.
Steps to change root EBS volume.
1.stop the instance
2.Create a new EBS volume
3.Detach the existing root EBS Volume
4.Attach the new EBS volume with the device name "/dev/xvda"
5.start the instance"\

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.

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.

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.

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.