Using Console
Using CLI
<AMI-ID>
with the actual ID of the unused AMI.<AMI-ID>
with the actual ID of the unused AMI. If the command returns an error stating that the AMI does not exist, then it has been successfully deregistered.By following the above steps, you can remediate the misconfiguration of unused AMIs in AWS using AWS CLI.Using Python
pip install boto3
boto3.Session()
method.
ec2
resource in Boto3 to get a list of all the AMIs currently available in your AWS account. You can use the filter()
method to filter out only the unused AMIs by checking their state
attribute. For example:
deregister_image()
method to remove them from your AWS account. For example: