-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolumes.py
More file actions
39 lines (31 loc) · 1.5 KB
/
volumes.py
File metadata and controls
39 lines (31 loc) · 1.5 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
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
print("| Region | Volume ID | Type | Size | IOPS | Throughput | Volume state | Attach resources |")
print("|--------------|---------------------|------|------|------|------------|--------------|------------------|")
regions = list_aws_regions()
for region in regions:
# Create an EC2 client
ec2 = boto3.client('ec2', region_name=region) # Modify the region as necessary
# Describe all volumes
volumes = ec2.describe_volumes()
# print(volumes)
# Print table head
# Print details for each volume
for volume in volumes['Volumes']:
# Extracting data
volume_id = volume['VolumeId']
volume_type = volume['VolumeType']
size = f"{volume['Size']} GiB"
iops = volume.get('Iops', 'N/A')
throughput = f"{volume.get('Throughput', 'N/A')} MB/s"
volume_state = volume['State']
attach_resources = "No attachments" if not volume['Attachments'] else ", ".join([attachment['InstanceId'] for attachment in volume['Attachments']])
# Print table row
print(f"| {region} | {volume_id} | {volume_type} | {size} | {iops} | {throughput} | {volume_state} | {attach_resources} |")