I need to delete all those hosted zones in Route53 using boto3
I created the zones in AWS console and trying to delete all those zones using boto3 using lamda function. I used the below codes however it throws error
import boto3
def lambda_handler(event, context):
# Iterate over regions
for region in regions:
# Running following for a particular region
print ("*************** Checking region -- %s " % region['RegionName'])
reg=region['RegionName']
########### cleaning Route53 zones ################
client = boto3.client('route53',region_name=reg)
response = client.list_hosted_zones_by_name()
for zone in response ['hosted-zones']:
print ("About to delete %s | in %s" % (zone['HostedZone'], region['RegionName']))
result = client.delete_hosted_zone(HostedZone=zone['HostedZone'])
Getting the following error message:
'hosted-zones': KeyError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 22, in lambda_handler
for zone in response ['hosted-zones']:
KeyError: 'hosted-zones'