-
-
Save filipeandre/0fa6dafa7cd07db5c36b589d16283d6d to your computer and use it in GitHub Desktop.
Route53 delete zone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def delete_zone(domain): | |
| """ Deleting a hosted zone in AWS is a real pain if you have any number of | |
| resource records defined because you must first delete all RR's in order to | |
| remove the zone. This is a one-stop script to do all of that in one command. | |
| """ | |
| import boto | |
| from boto.route53.record import ResourceRecordSets | |
| PROTECTED_DOMAINS = ['foo.com', 'bar.net'] | |
| if domain in PROTECTED_DOMAINS: | |
| print "NO DELETING " + domain + "!!!!" | |
| exit(1) | |
| conn = boto.connect_route53() | |
| zone = conn.get_zone(domain.lower().strip('.')) | |
| changes = ResourceRecordSets(conn, zone.id) | |
| records = zone.get_records() | |
| for record in records: | |
| if record.type != "NS" and record.type != "SOA": | |
| change = changes.add_change_record("DELETE", record) | |
| if len(changes.changes) > 0: | |
| result = changes.commit() | |
| zone.delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment