Last active
November 20, 2024 10:56
-
-
Save sybeck2k/6454134c6402052f5c164edafea86b7d to your computer and use it in GitHub Desktop.
A simple python script to get the total count of vCPUs for EC2 and RDS
This file contains 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
import boto3 | |
import requests | |
from datetime import datetime | |
import os | |
def get_all_regions(): | |
ec2_client = boto3.client('ec2', region_name='us-east-1') | |
response = ec2_client.describe_regions(AllRegions=True) | |
return [region['RegionName'] for region in response['Regions']] | |
def download_price_lists(service_code, currency_code="USD", effective_date=None): | |
if effective_date is None : | |
effective_date = datetime.now().strftime("%Y-%m-%d 00:00") | |
regions = get_all_regions() | |
pricing_client = boto3.client('pricing', region_name='us-east-1') | |
for region in regions: | |
print(f"Processing region: {region}") | |
try: | |
# List price lists | |
price_lists = pricing_client.list_price_lists( | |
ServiceCode=service_code, | |
CurrencyCode=currency_code, | |
EffectiveDate=effective_date, | |
RegionCode=region | |
) | |
if not price_lists.get('PriceLists'): | |
print(f"No price lists found for region {region}") | |
continue | |
for price_list in price_lists['PriceLists']: | |
price_list_arn = price_list['PriceListArn'] | |
# Get price list file URL | |
url_response = pricing_client.get_price_list_file_url( | |
PriceListArn=price_list_arn, | |
FileFormat='csv' | |
) | |
if 'Url' not in url_response: | |
print(f"Failed to get URL for price list {price_list_arn}") | |
continue | |
url = url_response['Url'] | |
# Download CSV | |
response = requests.get(url) | |
if response.status_code == 200: | |
filename = f"{service_code}_{region}_{effective_date.replace(' ', '_').replace(':', '')}.csv" | |
with open(filename, 'wb') as f: | |
f.write(response.content) | |
print(f"Downloaded: {filename}") | |
else: | |
print(f"Failed to download CSV for region {region}") | |
except Exception as e: | |
print(f"Error processing region {region}: {str(e)}") | |
if __name__ == "__main__": | |
service_code = input("Enter the AWS service code (e.g., AmazonGuardDuty): ") | |
currency_code = input("Enter the currency code (default: USD): ") or "USD" | |
while True: | |
effective_date_input = input("Enter the effective date (YYYY-MM-DD) or press Enter for today: ").strip() | |
if effective_date_input == "": | |
effective_date = None | |
break | |
try: | |
effective_date = datetime.strptime(effective_date_input, "%Y-%m-%d").date() | |
break | |
except ValueError: | |
print("Invalid date format. Please use YYYY-MM-DD.") | |
download_price_lists(service_code, currency_code, effective_date) | |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains 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
instance name;instance type;vcpus | |
T4G Micro;db.t4g.micro;2 vCPUs | |
T3 Micro;db.t3.micro;2 vCPUs | |
T2 General Purpose Micro;db.t2.micro;1 vCPUs | |
T1 Micro;db.t1.micro;1 vCPUs | |
T4G Small;db.t4g.small;2 vCPUs | |
T3 Small;db.t3.small;2 vCPUs | |
T2 General Purpose Small;db.t2.small;1 vCPUs | |
M1 General Purpose Small;db.m1.small;1 vCPUs | |
T4G Medium;db.t4g.medium;2 vCPUs | |
T3 Medium;db.t3.medium;2 vCPUs | |
T2 General Purpose Medium;db.t2.medium;2 vCPUs | |
M3 General Purpose Medium;db.m3.medium;1 vCPUs | |
M1 General Purpose Medium;db.m1.medium;1 vCPUs | |
T4G Large;db.t4g.large;2 vCPUs | |
T2 General Purpose Large;db.t2.large;2 vCPUs | |
T3 Large;db.t3.large;2 vCPUs | |
M6G Large;db.m6g.large;2 vCPUs | |
M7G Large;db.m7g.large;2 vCPUs | |
M6I Large;db.m6i.large;2 vCPUs | |
M5 Large;db.m5.large;2 vCPUs | |
M7I Large;db.m7i.large;2 vCPUs | |
M4 General Purpose Large;db.m4.large;2 vCPUs | |
M6GD Large;db.m6gd.large;2 vCPUs | |
M3 General Purpose Large;db.m3.large;2 vCPUs | |
M5D Large;db.m5d.large;2 vCPUs | |
M6ID Large;db.m6id.large;2 vCPUs | |
R6G Large;db.r6g.large;2 vCPUs | |
R7G Large;db.r7g.large;2 vCPUs | |
M1 General Purpose Large;db.m1.large;2 vCPUs | |
R5 Large;db.r5.large;2 vCPUs | |
R4 Memory Optimized Large;db.r4.large;2 vCPUs | |
R7I Large;db.r7i.large;2 vCPUs | |
R6I Large;db.r6i.large;2 vCPUs | |
R3 Memory Optimized Large;db.r3.large;2 vCPUs | |
R6GD Large;db.r6gd.large;2 vCPUs | |
T4G Extra Large;db.t4g.xlarge;4 vCPUs | |
M6IN Large;db.m6in.large;2 vCPUs | |
R5D Large;db.r5d.large;2 vCPUs | |
T3 Extra Large;db.t3.xlarge;4 vCPUs | |
T2 General Purpose Extra Large;db.t2.xlarge;4 vCPUs | |
M6IDN Large;db.m6idn.large;2 vCPUs | |
R5B Large;db.r5b.large;2 vCPUs | |
R6ID Large;db.r6id.large;2 vCPUs | |
M6G Extra Large;db.m6g.xlarge;4 vCPUs | |
X2G Large;db.x2g.large;2 vCPUs | |
M7G Extra Large;db.m7g.xlarge;4 vCPUs | |
M2 High Memory Extra Large;db.m2.xlarge;2 vCPUs | |
R6IN Large;db.r6in.large;2 vCPUs | |
M6I Extra Large;db.m6i.xlarge;4 vCPUs | |
M5 Extra Large;db.m5.xlarge;4 vCPUs | |
M7I Extra Large;db.m7i.xlarge;4 vCPUs | |
M4 General Purpose Extra Large;db.m4.xlarge;4 vCPUs | |
M6GD Extra Large;db.m6gd.xlarge;4 vCPUs | |
R6IDN Large;db.r6idn.large;2 vCPUs | |
M3 General Purpose Extra Large;db.m3.xlarge;4 vCPUs | |
M5D Extra Large;db.m5d.xlarge;4 vCPUs | |
M6ID Extra Large;db.m6id.xlarge;4 vCPUs | |
R6G Extra Large;db.r6g.xlarge;4 vCPUs | |
R7G Extra Large;db.r7g.xlarge;4 vCPUs | |
M1 General Purpose Extra Large;db.m1.xlarge;4 vCPUs | |
R7I Extra Large;db.r7i.xlarge;4 vCPUs | |
R5 Extra Large;db.r5.xlarge;4 vCPUs | |
R6I Extra Large;db.r6i.xlarge;4 vCPUs | |
R3 Memory Optimized Extra Large;db.r3.xlarge;4 vCPUs | |
R4 Memory Optimized Extra Large;db.r4.xlarge;4 vCPUs | |
R6GD Extra Large;db.r6gd.xlarge;4 vCPUs | |
M6IN Extra Large;db.m6in.xlarge;4 vCPUs | |
T4G Double Extra Large;db.t4g.2xlarge;8 vCPUs | |
R5D Extra Large;db.r5d.xlarge;4 vCPUs | |
T3 Double Extra Large;db.t3.2xlarge;8 vCPUs | |
T2 General Purpose Double Extra Large;db.t2.2xlarge;8 vCPUs | |
M6IDN Extra Large;db.m6idn.xlarge;4 vCPUs | |
R5B Extra Large;db.r5b.xlarge;4 vCPUs | |
R6ID Extra Large;db.r6id.xlarge;4 vCPUs | |
M6G Double Extra Large;db.m6g.2xlarge;8 vCPUs | |
X2G Extra Large;db.x2g.xlarge;4 vCPUs | |
M7G Double Extra Large;db.m7g.2xlarge;8 vCPUs | |
M2 High Memory Double Extra Large;db.m2.2xlarge;4 vCPUs | |
R6IN Extra Large;db.r6in.xlarge;4 vCPUs | |
M6I Double Extra Large;db.m6i.2xlarge;8 vCPUs | |
M5 Double Extra Large;db.m5.2xlarge;8 vCPUs | |
M7I Double Extra Large;db.m7i.2xlarge;8 vCPUs | |
M4 General Purpose Double Extra Large;db.m4.2xlarge;8 vCPUs | |
M6GD Double Extra Large;db.m6gd.2xlarge;8 vCPUs | |
M3 General Purpose Double Extra Large;db.m3.2xlarge;8 vCPUs | |
R6IDN Extra Large;db.r6idn.xlarge;4 vCPUs | |
M5D Double Extra Large;db.m5d.2xlarge;8 vCPUs | |
M6ID Double Extra Large;db.m6id.2xlarge;8 vCPUs | |
R6G Double Extra Large;db.r6g.2xlarge;8 vCPUs | |
R7G Double Extra Large;db.r7g.2xlarge;8 vCPUs | |
R3 Memory Optimized Double Extra Large;db.r3.2xlarge;8 vCPUs | |
R5 Double Extra Large;db.r5.2xlarge;8 vCPUs | |
R6I Double Extra Large;db.r6i.2xlarge;8 vCPUs | |
R7I Double Extra Large;db.r7i.2xlarge;8 vCPUs | |
R4 Memory Optimized Double Extra Large;db.r4.2xlarge;8 vCPUs | |
R6GD Double Extra Large;db.r6gd.2xlarge;8 vCPUs | |
M6IN Double Extra Large;db.m6in.2xlarge;8 vCPUs | |
R5D Double Extra Large;db.r5d.2xlarge;8 vCPUs | |
M6IDN Double Extra Large;db.m6idn.2xlarge;8 vCPUs | |
R5B Double Extra Large;db.r5b.2xlarge;8 vCPUs | |
R6ID Double Extra Large;db.r6id.2xlarge;8 vCPUs | |
M6G Quadruple Extra Large;db.m6g.4xlarge;16 vCPUs | |
X2G Double Extra Large;db.x2g.2xlarge;8 vCPUs | |
M7G Quadruple Extra Large;db.m7g.4xlarge;16 vCPUs | |
R6IN Double Extra Large;db.r6in.2xlarge;8 vCPUs | |
M2 High Memory Quadruple Extra Large;db.m2.4xlarge;8 vCPUs | |
M6I Quadruple Extra Large;db.m6i.4xlarge;16 vCPUs | |
M7I Quadruple Extra Large;db.m7i.4xlarge;16 vCPUs | |
M5 Quadruple Extra Large;db.m5.4xlarge;16 vCPUs | |
M4 General Purpose Quadruple Extra Large;db.m4.4xlarge;16 vCPUs | |
M6GD Quadruple Extra Large;db.m6gd.4xlarge;16 vCPUs | |
R6IDN Double Extra Large;db.r6idn.2xlarge;8 vCPUs | |
M5D Quadruple Extra Large;db.m5d.4xlarge;16 vCPUs | |
M6ID Quadruple Extra Large;db.m6id.4xlarge;16 vCPUs | |
R6G Quadruple Extra Large;db.r6g.4xlarge;16 vCPUs | |
R7G Quadruple Extra Large;db.r7g.4xlarge;16 vCPUs | |
R3 Memory Optimized Quadruple Extra Large;db.r3.4xlarge;16 vCPUs | |
R5 Quadruple Extra Large;db.r5.4xlarge;16 vCPUs | |
R6I Quadruple Extra Large;db.r6i.4xlarge;16 vCPUs | |
R4 Memory Optimized Quadruple Extra Large;db.r4.4xlarge;16 vCPUs | |
R7I Quadruple Extra Large;db.r7i.4xlarge;16 vCPUs | |
R6GD Quadruple Extra Large;db.r6gd.4xlarge;16 vCPUs | |
M6IN Quadruple Extra Large;db.m6in.4xlarge;16 vCPUs | |
X2IEDN Extra Large;db.x2iedn.xlarge;4 vCPUs | |
R5D Quadruple Extra Large;db.r5d.4xlarge;16 vCPUs | |
M6IDN Quadruple Extra Large;db.m6idn.4xlarge;16 vCPUs | |
R5B Quadruple Extra Large;db.r5b.4xlarge;16 vCPUs | |
R6ID Quadruple Extra Large;db.r6id.4xlarge;16 vCPUs | |
M6G Eight Extra Large;db.m6g.8xlarge;32 vCPUs | |
X2G Quadruple Extra Large;db.x2g.4xlarge;16 vCPUs | |
M7G Eight Extra Large;db.m7g.8xlarge;32 vCPUs | |
R6IN Quadruple Extra Large;db.r6in.4xlarge;16 vCPUs | |
M6I Eight Extra Large;db.m6i.8xlarge;32 vCPUs | |
M5 Eight Extra Large;db.m5.8xlarge;32 vCPUs | |
M7I Eight Extra Large;db.m7i.8xlarge;32 vCPUs | |
M6GD Eight Extra Large;db.m6gd.8xlarge;32 vCPUs | |
R6IDN Quadruple Extra Large;db.r6idn.4xlarge;16 vCPUs | |
M5D Eight Extra Large;db.m5d.8xlarge;32 vCPUs | |
M6ID Eight Extra Large;db.m6id.8xlarge;32 vCPUs | |
R6G Eight Extra Large;db.r6g.8xlarge;32 vCPUs | |
M4 General Purpose Deca Extra Large;db.m4.10xlarge;40 vCPUs | |
M6G 12xlarge;db.m6g.12xlarge;48 vCPUs | |
R7G Eight Extra Large;db.r7g.8xlarge;32 vCPUs | |
R3 Memory Optimized Eight Extra Large;db.r3.8xlarge;32 vCPUs | |
R5 Eight Extra Large;db.r5.8xlarge;32 vCPUs | |
R7I Eight Extra Large;db.r7i.8xlarge;32 vCPUs | |
R6I Eight Extra Large;db.r6i.8xlarge;32 vCPUs | |
R4 Memory Optimized Eight Extra Large;db.r4.8xlarge;32 vCPUs | |
M7G 12xlarge;db.m7g.12xlarge;48 vCPUs | |
R6GD Eight Extra Large;db.r6gd.8xlarge;32 vCPUs | |
M6IN Eight Extra Large;db.m6in.8xlarge;32 vCPUs | |
M5 12xlarge;db.m5.12xlarge;48 vCPUs | |
M6I 12xlarge;db.m6i.12xlarge;48 vCPUs | |
M7I 12xlarge;db.m7i.12xlarge;48 vCPUs | |
X2IEDN Double Extra Large;db.x2iedn.2xlarge;8 vCPUs | |
M6GD 12xlarge;db.m6gd.12xlarge;48 vCPUs | |
R5D Eight Extra Large;db.r5d.8xlarge;32 vCPUs | |
M6IDN Eight Extra Large;db.m6idn.8xlarge;32 vCPUs | |
R5B Eight Extra Large;db.r5b.8xlarge;32 vCPUs | |
R6ID Eight Extra Large;db.r6id.8xlarge;32 vCPUs | |
M5D 12xlarge;db.m5d.12xlarge;48 vCPUs | |
M6G 16xlarge;db.m6g.16xlarge;64 vCPUs | |
X2G Eight Extra Large;db.x2g.8xlarge;32 vCPUs | |
M6ID 12xlarge;db.m6id.12xlarge;48 vCPUs | |
M7G 16xlarge;db.m7g.16xlarge;64 vCPUs | |
R6G 12xlarge;db.r6g.12xlarge;48 vCPUs | |
R6IN Eight Extra Large;db.r6in.8xlarge;32 vCPUs | |
M6I 16xlarge;db.m6i.16xlarge;64 vCPUs | |
M7I 16xlarge;db.m7i.16xlarge;64 vCPUs | |
M5 16xlarge;db.m5.16xlarge;64 vCPUs | |
R7G 12xlarge;db.r7g.12xlarge;48 vCPUs | |
M4 General Purpose 16xlarge;db.m4.16xlarge;64 vCPUs | |
M6GD 16xlarge;db.m6gd.16xlarge;64 vCPUs | |
R7I 12xlarge;db.r7i.12xlarge;48 vCPUs | |
R5 12xlarge;db.r5.12xlarge;48 vCPUs | |
R6I 12xlarge;db.r6i.12xlarge;48 vCPUs | |
R6GD 12xlarge;db.r6gd.12xlarge;48 vCPUs | |
M6IN 12xlarge;db.m6in.12xlarge;48 vCPUs | |
R6IDN Eight Extra Large;db.r6idn.8xlarge;32 vCPUs | |
M5D 16xlarge;db.m5d.16xlarge;64 vCPUs | |
R5D 12xlarge;db.r5d.12xlarge;48 vCPUs | |
M6IDN 12xlarge;db.m6idn.12xlarge;48 vCPUs | |
R5B 12xlarge;db.r5b.12xlarge;48 vCPUs | |
R6ID 12xlarge;db.r6id.12xlarge;48 vCPUs | |
M6ID 16xlarge;db.m6id.16xlarge;64 vCPUs | |
R6G 16xlarge;db.r6g.16xlarge;64 vCPUs | |
R7G 16xlarge;db.r7g.16xlarge;64 vCPUs | |
X2G 12xlarge;db.x2g.12xlarge;48 vCPUs | |
R5 16xlarge;db.r5.16xlarge;64 vCPUs | |
R4 Memory Optimized 16xlarge;db.r4.16xlarge;64 vCPUs | |
R7I 16xlarge;db.r7i.16xlarge;64 vCPUs | |
R6I 16xlarge;db.r6i.16xlarge;64 vCPUs | |
R6GD 16xlarge;db.r6gd.16xlarge;64 vCPUs | |
M6IN 16xlarge;db.m6in.16xlarge;64 vCPUs | |
R6IN 12xlarge;db.r6in.12xlarge;48 vCPUs | |
M6I 24xlarge;db.m6i.24xlarge;96 vCPUs | |
M7I 24xlarge;db.m7i.24xlarge;96 vCPUs | |
M5 24xlarge;db.m5.24xlarge;96 vCPUs | |
X2IEDN Quadruple Extra Large;db.x2iedn.4xlarge;16 vCPUs | |
R5D 16xlarge;db.r5d.16xlarge;64 vCPUs | |
R6IDN 12xlarge;db.r6idn.12xlarge;48 vCPUs | |
M6IDN 16xlarge;db.m6idn.16xlarge;64 vCPUs | |
R5B 16xlarge;db.r5b.16xlarge;64 vCPUs | |
R6ID 16xlarge;db.r6id.16xlarge;64 vCPUs | |
M5D 24xlarge;db.m5d.24xlarge;96 vCPUs | |
X2G 16xlarge;db.x2g.16xlarge;64 vCPUs | |
M6ID 24xlarge;db.m6id.24xlarge;96 vCPUs | |
R6IN 16xlarge;db.r6in.16xlarge;64 vCPUs | |
M6I 32xlarge;db.m6i.32xlarge;128 vCPUs | |
R7I 24xlarge;db.r7i.24xlarge;96 vCPUs | |
R5 24xlarge;db.r5.24xlarge;96 vCPUs | |
R6I 24xlarge;db.r6i.24xlarge;96 vCPUs | |
M6IN 24xlarge;db.m6in.24xlarge;96 vCPUs | |
R6IDN 16xlarge;db.r6idn.16xlarge;64 vCPUs | |
R5D 24xlarge;db.r5d.24xlarge;96 vCPUs | |
M6IDN 24xlarge;db.m6idn.24xlarge;96 vCPUs | |
R5B 24xlarge;db.r5b.24xlarge;96 vCPUs | |
R6ID 24xlarge;db.r6id.24xlarge;96 vCPUs | |
M6ID 32xlarge;db.m6id.32xlarge;128 vCPUs | |
R6I 32xlarge;db.r6i.32xlarge;128 vCPUs | |
M6IN 32xlarge;db.m6in.32xlarge;128 vCPUs | |
R6IN 24xlarge;db.r6in.24xlarge;96 vCPUs | |
M7I 48xlarge;db.m7i.48xlarge;192 vCPUs | |
X2IEDN Eight Extra Large;db.x2iedn.8xlarge;32 vCPUs | |
R6IDN 24xlarge;db.r6idn.24xlarge;96 vCPUs | |
M6IDN 32xlarge;db.m6idn.32xlarge;128 vCPUs | |
R6ID 32xlarge;db.r6id.32xlarge;128 vCPUs | |
R6IN 32xlarge;db.r6in.32xlarge;128 vCPUs | |
R7I 48xlarge;db.r7i.48xlarge;192 vCPUs | |
R6IDN 32xlarge;db.r6idn.32xlarge;128 vCPUs | |
X2IEDN 16xlarge;db.x2iedn.16xlarge;64 vCPUs | |
X2IEDN 24xlarge;db.x2iedn.24xlarge;96 vCPUs | |
X2IEDN 32xlarge;db.x2iedn.32xlarge;128 vCPUs | |
R6I Double Extra Large;db.r6i.2xlarge.tpc2.mem8x;8 vCPUs | |
R5 Quadruple Extra Large;db.r5.4xlarge.tpc2.mem4x;16 vCPUs | |
R5 Double Extra Large;db.r5.2xlarge.tpc2.mem4x;8 vCPUs | |
R5 Double Extra Large;db.r5.2xlarge.tpc2.mem8x;8 vCPUs | |
R5B Double Extra Large;db.r5b.2xlarge.tpc2.mem4x;8 vCPUs | |
R5B Large;db.r5b.large.tpc1.mem2x;2 vCPUs | |
X1E Double Extra Large;db.x1e.2xlarge;8 vCPUs | |
R5 Extra Large;db.r5.xlarge.tpc2.mem2x;4 vCPUs | |
X1 32xlarge;db.x1.32xlarge;128 vCPUs | |
R6I Quadruple Extra Large;db.r6i.4xlarge.tpc2.mem2x;16 vCPUs | |
X2IDN 24xlarge;db.x2idn.24xlarge;96 vCPUs | |
Z1D Double Extra Large;db.z1d.2xlarge;8 vCPUs | |
X1E 16xlarge;db.x1e.16xlarge;64 vCPUs | |
R6I Double Extra Large;db.r6i.2xlarge.tpc1.mem2x;8 vCPUs | |
X1E Quadruple Extra Large;db.x1e.4xlarge;16 vCPUs | |
R5B Extra Large;db.r5b.xlarge.tpc2.mem4x;4 vCPUs | |
Z1D Extra Large;db.z1d.xlarge;4 vCPUs | |
R6I Extra Large;db.r6i.xlarge.tpc2.mem2x;4 vCPUs | |
R5 6xlarge;db.r5.6xlarge.tpc2.mem4x;24 vCPUs | |
R6I Extra Large;db.r6i.xlarge.tpc2.mem4x;4 vCPUs | |
R5B Quadruple Extra Large;db.r5b.4xlarge.tpc2.mem2x;16 vCPUs | |
Z1D 3xlarge;db.z1d.3xlarge;12 vCPUs | |
R5 Large;db.r5.large.tpc1.mem2x;2 vCPUs | |
R6I Quadruple Extra Large;db.r6i.4xlarge.tpc2.mem4x;16 vCPUs | |
R6I Double Extra Large;db.r6i.2xlarge.tpc2.mem4x;8 vCPUs | |
R5 Double Extra Large;db.r5.2xlarge.tpc1.mem2x;8 vCPUs | |
R6I Eight Extra Large;db.r6i.8xlarge.tpc2.mem4x;32 vCPUs | |
R5B Quadruple Extra Large;db.r5b.4xlarge.tpc2.mem3x;16 vCPUs | |
X1E Eight Extra Large;db.x1e.8xlarge;32 vCPUs | |
X2IEZN Quadruple Extra Large;db.x2iezn.4xlarge;16 vCPUs | |
Z1D Large;db.z1d.large;2 vCPUs | |
R5 Quadruple Extra Large;db.r5.4xlarge.tpc2.mem2x;16 vCPUs | |
R5B 6xlarge;db.r5b.6xlarge.tpc2.mem4x;24 vCPUs | |
R6I 12xlarge;db.r6i.12xlarge.tpc2.mem2x;48 vCPUs | |
X1E 32xlarge;db.x1e.32xlarge;128 vCPUs | |
R6I Quadruple Extra Large;db.r6i.4xlarge.tpc2.mem3x;16 vCPUs | |
R5B Extra Large;db.r5b.xlarge.tpc2.mem2x;4 vCPUs | |
R5 Quadruple Extra Large;db.r5.4xlarge.tpc2.mem3x;16 vCPUs | |
X1 16xlarge;db.x1.16xlarge;64 vCPUs | |
Z1D 12xlarge;db.z1d.12xlarge;48 vCPUs | |
X2IDN 32xlarge;db.x2idn.32xlarge;128 vCPUs | |
R6I 6xlarge;db.r6i.6xlarge.tpc2.mem4x;24 vCPUs | |
X1E Extra Large;db.x1e.xlarge;4 vCPUs | |
Z1D 6xlarge;db.z1d.6xlarge;24 vCPUs | |
X2IDN 16xlarge;db.x2idn.16xlarge;64 vCPUs | |
R5B Double Extra Large;db.r5b.2xlarge.tpc2.mem8x;8 vCPUs | |
R5B Eight Extra Large;db.r5b.8xlarge.tpc2.mem3x;32 vCPUs | |
R6I Large;db.r6i.large.tpc1.mem2x;2 vCPUs | |
R5 12xlarge;db.r5.12xlarge.tpc2.mem2x;48 vCPUs | |
R5 Extra Large;db.r5.xlarge.tpc2.mem4x;4 vCPUs | |
R5B Quadruple Extra Large;db.r5b.4xlarge.tpc2.mem4x;16 vCPUs | |
R5 Eight Extra Large;db.r5.8xlarge.tpc2.mem3x;32 vCPUs | |
R5B Double Extra Large;db.r5b.2xlarge.tpc1.mem2x;8 vCPUs | |
X2IEZN Double Extra Large;db.x2iezn.2xlarge;8 vCPUs | |
R6I Eight Extra Large;db.r6i.8xlarge.tpc2.mem3x;32 vCPUs | |
X2IEZN Eight Extra Large;db.x2iezn.8xlarge;32 vCPUs | |
X2IEZN 6xlarge;db.x2iezn.6xlarge;24 vCPUs | |
X2IEZN 12xlarge;db.x2iezn.12xlarge;48 vCPUs | |
R6I Quadruple Extra Large;db.r6i.4xlarge.tpc2.mem8x;16 vCPUs |
This file contains 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
import boto3 | |
import csv | |
from collections import defaultdict | |
def load_rds_vcpu_info(csv_file): | |
vcpu_info = {} | |
with open(csv_file, 'r') as file: | |
csv_reader = csv.reader(file, delimiter=';') | |
next(csv_reader) # Skip the header row | |
for row in csv_reader: | |
if len(row) == 3: | |
_, instance_type, vcpus = row | |
if vcpus.endswith('vCPUs'): | |
vcpu_count = int(vcpus.split()[0]) | |
vcpu_info[instance_type.strip()] = vcpu_count | |
return vcpu_info | |
def get_ec2_total_vcpu_count(region): | |
# Create EC2 client | |
ec2 = boto3.client('ec2', region_name=region) | |
# Initialize total vCPU count | |
total_vcpu = 0 | |
# Get all instance types | |
vcpus_per_instance_types = defaultdict(int) | |
instance_types = {} | |
paginator = ec2.get_paginator('describe_instance_types') | |
for page in paginator.paginate(): | |
for instance_type in page['InstanceTypes']: | |
instance_types[instance_type['InstanceType']] = instance_type['VCpuInfo']['DefaultVCpus'] | |
instance_types_usage = defaultdict(int) | |
# Paginate through all instances | |
paginator = ec2.get_paginator('describe_instances') | |
for page in paginator.paginate(): | |
for reservation in page['Reservations']: | |
for instance in reservation['Instances']: | |
# Check if instance is running | |
if instance['State']['Name'] == 'running': | |
instance_type = instance['InstanceType'] | |
if instance_type in instance_types: | |
total_vcpu += instance_types[instance_type] | |
vcpus_per_instance_types[instance_type] += instance_types[instance_type] | |
return vcpus_per_instance_types | |
def get_rds_total_vcpu_count(region): | |
# Load vCPU information from CSV | |
rds_vcpu_info = load_rds_vcpu_info('rds_instance_vcpu.csv') | |
# Initialize RDS client | |
rds_client = boto3.client('rds', region_name=region) | |
# Get all RDS instances | |
paginator = rds_client.get_paginator('describe_db_instances') | |
instance_types = defaultdict(int) | |
# Collect instance types | |
for page in paginator.paginate(): | |
for instance in page['DBInstances']: | |
instance_type = instance['DBInstanceClass'] | |
instance_types[instance_type] += 1 | |
instance_types_usage = defaultdict(int) | |
for instance_type, count in instance_types.items(): | |
vcpus = rds_vcpu_info.get(instance_type, "Unknown") | |
if vcpus != "Unknown": | |
total_vcpus_for_type = vcpus * count | |
instance_types_usage[instance_type] += total_vcpus_for_type | |
else: | |
raise Exception(f"Missing data for instance type {instance_type}") | |
return instance_types_usage | |
def main(): | |
region = 'eu-west-1' | |
ec2_vcpus = get_ec2_total_vcpu_count(region) | |
rds_vcpus = get_rds_total_vcpu_count(region) | |
# Calculate and print results | |
total_rds_vcpus = 0 | |
print("RDS:") | |
print("Instance Type | Total vCPUs") | |
print("-" * 60) | |
for instance_type, vcpus in rds_vcpus.items(): | |
total_rds_vcpus += vcpus | |
print(f"{instance_type:14} | {vcpus:18}") | |
print(f"Total RDS vCPUS: {total_rds_vcpus}") | |
print("") | |
print("EC2:") | |
# Calculate and print results | |
total_ec2_vcpus = 0 | |
print("Instance Type | Total vCPUs") | |
print("-" * 60) | |
for instance_type, vcpus in ec2_vcpus.items(): | |
total_ec2_vcpus += vcpus | |
print(f"{instance_type:14} | {vcpus:18}") | |
print(f"Total EC2 vCPUS: {total_ec2_vcpus}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment