{"id":17623,"date":"2015-02-28T00:50:10","date_gmt":"2015-02-27T19:20:10","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=17623"},"modified":"2015-03-03T14:45:25","modified_gmt":"2015-03-03T09:15:25","slug":"find-ebs-snapshot-using-python-boto","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/find-ebs-snapshot-using-python-boto\/","title":{"rendered":"Find EBS snapshot using python boto"},"content":{"rendered":"<p><span style=\"color: #000000\">Since we have already covered the basic configuration and installation of boto in the previous blog by <a href=\"http:\/\/www.tothenew.com\/blog\/getting-started-with-boto-python-interface-for-aws\">@Vikash<\/a>, Here we will be discussing about one of the common use case of daily routine.<\/span><\/p>\n<p><span style=\"color: #000000\">In this script we will find out the snapshot of the particular volume in specific region.So parameter to find the snapshots are<\/span><\/p>\n<ul>\n<li><span style=\"color: #000000\">Region:In which region we need to find the snapshots<\/span><\/li>\n<li><span style=\"color: #000000\">Volume id:This will pass as argument to find the snapshots<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000\">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\u2019ll want to do something like line 2.<\/span><\/p>\n<p><span style=\"color: #000000\">Now first we get the ec2.connect_to_region(&#8216;ap-southeast-1&#8217;) object,to get the access of the region.\u00a0Note that this is available due to the \u201cfrom..import\u201d above.Next, use the method &#8220;get_all_snapshots()&#8221; along with filters to get the snapshots details along with volume id.<\/span><\/p>\n<p><span style=\"color: #ff9900\">Script :<\/span><\/p>\n<p>[js]<br \/>\n#!\/usr\/bin\/python<br \/>\nimport boto<br \/>\nimport sys<br \/>\nfrom boto import ec2<br \/>\nconnection=ec2.connect_to_region(&#8216;ap-southeast-1&#8217;)<br \/>\nsnapshots=connection.get_all_snapshots(filters={&#8216;volume-id&#8217;:sys.argv})<br \/>\nfor snaps in snapshots:<br \/>\n    print snaps.id,&quot;-&quot;,snaps.start_time, &quot;-&quot;,snaps.volume_size, &quot;\\n&quot;<br \/>\n[\/js]<\/p>\n<p><span style=\"color: #ff9900\">To Run script:<\/span><\/p>\n<p>[js] python script.py vol-xxeaxxx [\/js]<\/p>\n<p>Thanks<br \/>\nPrashant Sharma<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":120,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[1174],"tags":[1611,1358],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/17623"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/120"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=17623"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/17623\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=17623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=17623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=17623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}