-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute_53.py
More file actions
41 lines (28 loc) · 1.1 KB
/
route_53.py
File metadata and controls
41 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import boto3
def list_aws_regions():
# Initialize the EC2 client with default region
ec2 = boto3.client('ec2')
# Retrieve all regions that work with EC2
response = ec2.describe_regions()
# Extract region names from the response
regions = [region['RegionName'] for region in response['Regions']]
return regions
def list_route53_hosted_zones(region):
# Initialize a Route 53 client for the specified region
route53 = boto3.client('route53', region_name=region)
# List hosted zones in Route 53
response = route53.list_hosted_zones()
hosted_zones = response.get('HostedZones', [])
return hosted_zones
# Get all AWS regions
regions = list_aws_regions()
# Print table headers
print("| Region | Hosted Zone ID | Name |")
print("|--------|----------------|------|")
# Iterate over each region
for region in regions:
# List hosted zones in Route 53 for the region
hosted_zones = list_route53_hosted_zones(region)
# Print hosted zones
for zone in hosted_zones:
print(f"| {region} | {zone['Id'].split('/')[-1]} | {zone['Name']} |")