Recently, repeated instance start / stop and backup A lot of Volumes when I noticed by snapping for AMI creation. ..
Many EBSs are made (available) even though they are not "in-use", If you check the billing status with Account Activity, this is increasing soberly.
Amazon EC2 EBS $0.12 per GB-month of provisioned storage .....
Try it and feel it on your skin! From an instance with 3 EBS volumes attached From creating an AMI.
Amazon EC2 EBS $0.1 per GB-Month of snapshot data stored
Purpose
I want to reduce waste
Overview
As you can see from the above, when you create an AMI, SNAP is created, and when you start an instance, a new Volume is created.
If you know only what you made yesterday, you can erase unnecessary things while your memory is hot the next day!
I want to automate it eventually. .. .. The automatic deletion is a little scary, so I'll come back later.
Operating environment
CentOS6.3
Python 2.6.6
boto-2.6.0
aws-cli/0.12.0
daily_check_ebs_created.py
#!/usr/bin/python
#-*- coding: utf-8 -*-
import commands
import sys,getopt
import json
import datetime
from datetime import datetime as dt
# Set standard date
aday = datetime.timedelta(days=1)
std_day = datetime.datetime.today() - aday
# Exec command
aws_cmd='aws ec2 describe-volumes'
out=commands.getoutput(aws_cmd)
# Parse JSON
ebs_data = json.loads(out)
print "===================================================================="
print "The following refers to the volume that is created after this time. "
print unicode(std_day)
print "===================================================================="
for vols in ebs_data["Volumes"]:
cretime = dt.strptime(vols["CreateTime"], '%Y-%m-%dT%H:%M:%S.000Z')
## Volume only newly created
if cretime > std_day:
print "AZ=" + vols["AvailabilityZone"] + ", volId=" + vols["VolumeId"] + ", CreateTime=" + unicode(cretime) + ", State=" + vols["State"]
export AWS_DEFAULT_REGION=ap-northeast-1
It's not such a big code w However, the ones that can be used soberly are up.
However, "usable" and "unusable" are also subjective, so Start by writing something that is simple and "usable" by yourself.