[AWS] EBS creation status check tool

EBS creation status check tool

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 .....

About volume operation and billing

Try it and feel it on your skin! From an instance with 3 EBS volumes attached From creating an AMI.


  1. Create AMI EBS_a-1.jpg
  2. SNAP, Volume confirmation SNAP is possible. (And now I notice that Progress is a bar display.) EBS_a-2.jpg
  1. Delete AMI Disappear beautifully
  2. SNAP, Volume confirmation SNAP remains

Amazon EC2 EBS $0.1 per GB-Month of snapshot data stored


  1. Create AMI EBS_b-1.jpg
  2. SNAP, Volume confirmation Like [a], SNAP can be done, but Volume cannot. .. EBS_b-2.jpg
  3. Remove SNAP Yes, I can't erase it! !! Sorry! That's right, SNAP cannot be erased because it is one element of the image storage configuration. EBS_b-3.jpg

  1. Launch an instance from the AMI created in [b] Please turn off "Delete on Termination". (People who are familiar with this area are likely to be spoiled ...) EBS_c-1.jpg
  2. SNAP, Volume confirmation SNAP cannot be newly created (naturally), but Volume is newly expanded from SNAP and is an instance. EBS_c-2.jpg
  3. Terminate the instance and delete Volume EBS_c-3.jpg
  4. Neither SNAP nor AMI disappears! (Of course!!)

I made a tool

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

See below

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.

Recommended Posts

[AWS] EBS creation status check tool
Reconfirmation of AWS EBS
Tool to check code style
Regular expression check tool summary