AWS how to find Snapshot associated with AMI? - amazon-web-services

I am trying to find a AWS Snapshot associated with AMI.
I am cleaning up my AMI list. After deregistering 2 AMI I have checked snapshot count its not reducing any reason behind this?
How can delete snapshot associated with AMI automatically when I am deleting AMI?

When you deregister an Amazon EBS-backed AMI, it doesn't affect the snapshot that was created for the root volume of the instance during the AMI creation process. You'll continue to incur storage costs for this snapshot. Therefore, if you are finished with the snapshot, you should delete it.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/deregister-ami.html
And for writing some automation script, which can auto delete snapshots when you are deleting the AMI, you can have a look on following:
https://serverfault.com/questions/611831/find-all-snapshots-created-by-ami-where-ami-is-deleted
https://www.yobyot.com/aws/deregister-an-aws-ami-and-remove-associated-s3-snapshots/2014/10/30/
http://www.n2ws.com/how-to-guides/how-to-delete-unutilized-ebs-based-amis-and-corresponding-snapshots.html

Related

Restoring snapshot to new EBS volume in Terraform

I'm looking at creating a disaster recovery script on AWS for restoring servers.
I've written the Terraform script to create a new EC2 instance, but I'd like to restore a snapshot from the old EBS volume to a new one and then attach that to the new EC2 instance.
I've been looking through Terraform though and can't see a way to restore a snapshot to a new volume, is it possible?

AMIs snapshots without associated volumes

I have a few AMIs stored with snapshot associated with their storage definitions. However, the volumes that are associated with those snapshots have been deleted to save costs.
Can the AMIs still be used?
Yes, because snapshot is a backup of your volume. The original volume does not have to exist for the snapshot to be useful. You can always create a volume from a snapshot.
If you want to double check this, you can spin up basic t2.micro instance, take it snapshot, delete the instance and any associated volumes (root volume will be automatically deleted). Then you can launch new instance from the snapshot created.

AWS Snapshots not saving data

I created several snapshots from volumes of my instances months ago. Today I had to restore an instance based on a snapshot, but this instance does not contain any of my data, it is a clean version of Ubuntu, exactly as the first time I created the instance.
How do I restore my data?
thanks
In AWS there are two snapshot options:
1- Snapshot: You can use snapshots to capture a point-in-time state of your individual volumes.
2- Amazon Machine Image (AMI): You can use an AMI to capture a point-in-time state of your whole EC2 instance (VM), including all of its volumes.
So, difference is that snapshot is on individual volume level and AMI is the entire instance. Under the hood, AMI takes snapshots of all attached volumes and you can see those snapshots in the corresponding Snapshots page in AWS Management Console.
So to be clear, did you create an AMI from you Ubuntu instance and restored the same AMI? Or did you create a snapshot from one or more of its volumes? In that case, how did you restore it?
If you only take a snapshot of one or more of the volumes, after you restore your snapshots into new volumes attached to an instance, you should also remember to mount those volumes. But if you use an AMI, mounting may not be required, as long as you have added your volumes in the /etc/fstab.

Finding out AMI associated with an instance

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

Does new instance from AMI generated from EBS snapshots require initialization

I understand that EBS volumes that are restored from snapshots need to be initialized.
Let's say I create an AMI from an EBS snapshot(s).
When I launch a new instance using that AMI, will I need to initialize each volume before I get consistent latency?
When you create an instance from AMI which has EBS based volumes as storage, your instance creates new volume from this volume and continues with launch.
When you use snapshots as source to launch your instance, AWS need to pull these snapshots and write it to volume and then continue with the launch. In this case, pull storage blocks from S3 and write to volume will be the latency some users want to avoid. This is the case where pre-warming is suggested by AWS.