Amazon EC2 Pictures

I used CreateImageRequestto take a picture of a running EC2 machine. When I enter the EC2 console, I see the following:

  • AMI is an image that I can run
  • Volume - I think this is a disk image?
  • Snapshot - another snapshot related entry?

Can someone explain the difference in the use of each of them? For example, is there a way to create a “snapshot” without using the associated “AMI”, in which case, how do I back up this EBS-enabled snapshot?

Finally, is there a simple API to remove AMI and all associated data (snapshot, scope, and AMI). It turns out that our scripts store only the AMI and not the rest of the data, and therefore it seems that there is enough information to just unregister the image.

+3
source share
2 answers

AMI is a configuration of a running machine - it actually does not contain any machine data, but simply refers to it. AMI can get an image of its disk either from S3, or (in your case) with an EBS snapshot.

The amount of EBS associated with the running instance. This is basically a read-write disk image. When you complete the instance, the volume will be automatically destroyed (this may take several minutes, note).

- EBS , AMI. AMI, AMI - .

AMI, EBS, . , , .

, AMI, API DescribeImageAttribute AMI blockDeviceMapping ; AMI .

+7

PS script AMI ( ), AMI, , , ( ).

# Unregister and clean AMI snapshots
$amiName = 'ami-XXXX' # replace this with the AMI ID you need to clean-up
$myImage = Get-EC2Image $amiName
$count = $myImage[0].BlockDeviceMapping.Count

# Loop and store snapshotID(s) to an array
$mySnaps = @()
for ($i=0; $i -lt $count; $i++)
{
 $snapId = $myImage[0].BlockDeviceMapping[$i].Ebs | foreach {$_.SnapshotId}
 $mySnaps += $snapId
}

# Perform the clean up
Write-Host "Unregistering" $amiName
Unregister-EC2Image $amiName
foreach ($item in $mySnaps)
{
  Write-Host 'Removing' $item
  Remove-EC2Snapshot $item
}

Clear-Variable mySnaps
+1

Source: https://habr.com/ru/post/1788569/


All Articles