Search code examples
python-2.7amazon-web-servicesboto

How to check whether a snapshot with ID is in use of AWS AMI's in Boto?


I am getting the following Error while deleting snapshots. I wanted to delete Snapshot which are currently not in use by My AWS AMI's and Other Instances.. as well .I tried but got this error..

Traceback (most recent call last):
<path to error file>
EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?><Response><Errors><Error><Code>InvalidSnapshot.InUse</Code><Message>The snapshot snap-xxxxxxxx is currently in use by ami-xxxxxxxx</Message></Error></Errors><RequestID>bbe55333-4acf-4ca7-9aa3-49307b189ca3</RequestID></Response>

Solution

  • Unfortunately, there is not an API to get AMI ID directly from an EBS snapshot.

    Instead, you can go the other way.

    1. Use ec2:DescribeImages to get a list of AMI images.
    2. For each AMI image returned, examine the list of EBS snapshots associated with the AMI image.
    3. See if the EBS snapshot in question is included.

    Edit: Another possibility:

    You may be able to use ec2:DescribeImages with a filter on the EBS snapshot ID.

    https://ec2.amazonaws.com/?Action=DescribeImages
     &Filter.1.Name=block-device-mapping.snapshot-id
     &Filter.1.Value=snap-xxxx
    

    Reference: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html