Since we have already covered the basic configuration and installation of boto in the previous blog by @Vikash, Here we will be discussing about one of the common use case of daily routine.
In this script we will find out the snapshot of the particular volume in specific region.So parameter to find the snapshots are
- Region:In which region we need to find the snapshots
- Volume id:This will pass as argument to find the snapshots
Lets talk about the script where we got the typical shebang , which invokes the python interpreter and execute the script directly. Now most important part: importing boto. The first import which is really required by us, but if you want to be able to reference parts of the boto library without fully qualifying them,you’ll want to do something like line 2.
Now first we get the ec2.connect_to_region(‘ap-southeast-1’) object,to get the access of the region. Note that this is available due to the “from..import” above.Next, use the method “get_all_snapshots()” along with filters to get the snapshots details along with volume id.
from boto import ec2
for snaps in snapshots:
print snaps.id,"-",snaps.start_time, "-",snaps.volume_size, "\n"
To Run script:
[js] python script.py vol-xxeaxxx [/js]