Last active
May 14, 2023 08:23
-
-
Save shimo164/c09b5769848509a4c5173660cce97a9d to your computer and use it in GitHub Desktop.
Compare the availability of AWS services across two specified regions
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
""" | |
This script compares the availability of AWS services across two specified | |
regions (region1 and region2) and outputs the results. Prints the results, | |
showing the count and names of the services in each category (common, | |
region-specific, and not available). | |
Parameters: | |
- region1 (str): The first AWS region | |
- region2 (str): The second AWS region | |
Requirements: | |
- requests library | |
Usage: | |
- Set `region1` and `region2` to the desired regions. | |
- Run python3 this_script.py | |
""" | |
import json | |
import requests | |
# Set two regions for comparison | |
region1 = "ap-northeast-1" | |
region2 = "ap-northeast-3" | |
# Fetch the JSON data from the URL | |
url = "https://aws-new-features.s3.amazonaws.com/html/aws_services.json" | |
response = requests.get(url) | |
# Check if the request was successful | |
if response.status_code == 200: | |
aws_services = response.text | |
else: | |
print(f"Error fetching data from {url}. Status code: {response.status_code}") | |
exit(1) | |
# Load the JSON data | |
data = json.loads(aws_services) | |
# Initialize sets to store services available in each region | |
set1 = set() | |
set2 = set() | |
# Iterate through the services | |
for service, regions in data.items(): | |
if region1 in regions: | |
set1.add(service) | |
if region2 in regions: | |
set2.add(service) | |
# Compare services available in both regions | |
common_services = set1.intersection(set2) | |
region1_specific_services = set1.difference(set2) | |
region2_specific_services = set2.difference(set1) | |
all_services = set(data.keys()) | |
not_available_either_region = all_services.difference(set1.union(set2)) | |
def print_count_and_services(services: set): | |
print(f"Count: {len(services)}") | |
services_list = sorted(list(services)) | |
print(services_list) | |
print("---") | |
print(f"Services available in both {region1} and {region2}:") | |
print_count_and_services(common_services) | |
if region1_specific_services: | |
print(f"Services available only in {region1}:") | |
print_count_and_services(region1_specific_services) | |
else: | |
print(f"No services available only in {region1}") | |
if region2_specific_services: | |
print(f"Services available only in {region2}:") | |
print_count_and_services(region2_specific_services) | |
else: | |
print(f"No services available only in {region2}") | |
print("---") | |
print(f"Services not available in either {region1} or {region2}:") | |
print_count_and_services(not_available_either_region) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment