def inventory_regions(vendor):
"""List all available AWS regions via `boto3` calls.
Some data sources are not available from APIs, and were collected manually:
- launch date: <https://aws.amazon.com/about-aws/global-infrastructure/regions_az/>,
- energy source: <https://sustainability.aboutamazon.com/products-services/the-cloud?energyType=true#renewable-energy>,
- lon/lat coordinates: <https://gist.github.com/martinheidegger/88950cb51ee5bdeafd51bc55287b1092> and approximation based on the city when no more accurate data was available.
""" # noqa: E501
regions = [
{
"region_id": "af-south-1",
"name": "Africa (Cape Town)",
"vendor_id": vendor.vendor_id,
"country_id": "ZA",
"city": "Cape Town",
"founding_year": 2020,
"green_energy": False,
"lat": -33.914651,
"lon": 18.3758801,
},
{
"region_id": "ap-east-1",
"name": "Asia Pacific (Hong Kong)",
"vendor_id": vendor.vendor_id,
"country_id": "HK",
"city": "Hong Kong",
"founding_year": 2019,
"green_energy": False,
"lat": 22.2908475,
"lon": 114.2723379,
},
{
"region_id": "ap-northeast-1",
"name": "Asia Pacific (Tokyo)",
"vendor_id": vendor.vendor_id,
"country_id": "JP",
"city": "Tokyo",
"founding_year": 2011,
"green_energy": False,
"lat": 35.617436,
"lon": 139.7459176,
},
{
"region_id": "ap-northeast-2",
"name": "Asia Pacific (Seoul)",
"vendor_id": vendor.vendor_id,
"country_id": "KR",
"city": "Seoul",
"founding_year": 2016,
"green_energy": False,
"lat": 37.5616592,
"lon": 126.8736237,
},
{
"region_id": "ap-northeast-3",
"name": "Asia Pacific (Osaka)",
"vendor_id": vendor.vendor_id,
"country_id": "JP",
"city": "Osaka",
"founding_year": 2021,
"green_energy": False,
"lat": 34.693889,
"lon": 135.502222,
},
{
"region_id": "ap-south-1",
"name": "Asia Pacific (Mumbai)",
"vendor_id": vendor.vendor_id,
"country_id": "IN",
"city": "Mumbai",
"founding_year": 2016,
"green_energy": True,
"lat": 19.2425503,
"lon": 72.9667878,
},
{
"region_id": "ap-south-2",
"name": "Asia Pacific (Hyderabad)",
"vendor_id": vendor.vendor_id,
"country_id": "IN",
"city": "Hyderabad",
"founding_year": 2022,
"green_energy": True,
# approximation based on city location
"lat": 17.412281,
"lon": 78.243237,
},
{
"region_id": "ap-southeast-1",
"name": "Asia Pacific (Singapore)",
"vendor_id": vendor.vendor_id,
"country_id": "SG",
"city": "Singapore",
"founding_year": 2010,
"green_energy": False,
"lat": 1.3218269,
"lon": 103.6930643,
},
{
"region_id": "ap-southeast-2",
"name": "Asia Pacific (Sydney)",
"vendor_id": vendor.vendor_id,
"country_id": "AU",
"city": "Sydney",
"founding_year": 2012,
"green_energy": False,
"lat": -33.9117717,
"lon": 151.1907535,
},
{
"region_id": "ap-southeast-3",
"name": "Asia Pacific (Jakarta)",
"vendor_id": vendor.vendor_id,
"country_id": "ID",
"city": "Jakarta",
"founding_year": 2021,
"green_energy": False,
"lat": -6.2,
"lon": 106.816667,
},
{
"region_id": "ap-southeast-4",
"name": "Asia Pacific (Melbourne)",
"vendor_id": vendor.vendor_id,
"country_id": "AU",
"city": "Melbourne",
"founding_year": 2023,
"green_energy": False,
# approximation based on city location
"lat": -37.8038607,
"lon": 144.7119569,
},
{
"region_id": "ca-central-1",
"name": "Canada (Central)",
"vendor_id": vendor.vendor_id,
"country_id": "CA",
"city": "Quebec", # NOTE needs city name
"founding_year": 2016,
"green_energy": True,
"lat": 45.5,
"lon": -73.6,
},
{
"region_id": "ca-west-1",
"name": "Canada West (Calgary)",
"vendor_id": vendor.vendor_id,
"country_id": "CA",
"city": "Calgary",
"founding_year": 2023,
"green_energy": False,
# approximation based on city location
"lat": 51.046574,
"lon": -114.129024,
},
{
"region_id": "cn-north-1",
"name": "China (Beijing)",
"vendor_id": vendor.vendor_id,
"country_id": "CN",
"city": "Beijing",
"founding_year": 2016,
"green_energy": True,
"lat": 39.8094478,
"lon": 116.5783234,
},
{
"region_id": "cn-northwest-1",
"name": "China (Ningxia)",
"vendor_id": vendor.vendor_id,
"country_id": "CN",
"city": "Ningxia", # NOTE needs city name
"founding_year": 2017,
"green_energy": True,
"lat": 37.5024418,
"lon": 105.1627193,
},
{
"region_id": "eu-central-1",
"name": "Europe (Frankfurt)",
"aliases": ["EU (Frankfurt)"],
"vendor_id": vendor.vendor_id,
"country_id": "DE",
"city": "Frankfurt",
"founding_year": 2014,
"green_energy": True,
"lat": 50.0992094,
"lon": 8.6303932,
},
{
"region_id": "eu-central-2",
"name": "Europe (Zurich)",
"vendor_id": vendor.vendor_id,
"country_id": "CH",
"city": "Zurich",
"founding_year": 2022,
"green_energy": True,
# approximation based on city location
"lat": 47.3862924,
"lon": 8.4448814,
},
{
"region_id": "eu-north-1",
"name": "Europe (Stockholm)",
"aliases": ["EU (Stockholm)"],
"vendor_id": vendor.vendor_id,
"country_id": "SE",
"city": "Stockholm",
"founding_year": 2018,
"green_energy": True,
"lat": 59.326242,
"lon": 17.8419717,
},
{
"region_id": "eu-south-1",
"name": "Europe (Milan)",
"aliases": ["EU (Milan)"],
"vendor_id": vendor.vendor_id,
"country_id": "IT",
"city": "Milan",
"founding_year": 2020,
"green_energy": True,
"lat": 45.4628328,
"lon": 9.1076927,
},
{
"region_id": "eu-south-2",
"name": "Europe (Spain)",
"vendor_id": vendor.vendor_id,
"country_id": "ES",
"city": "Aragón", # NOTE needs city name
"founding_year": 2022,
"green_energy": True,
# approximation based on city location
"lat": 41.7943702,
"lon": -0.8516735,
},
{
"region_id": "eu-west-1",
"name": "Europe (Ireland)",
"aliases": ["EU (Ireland)"],
"vendor_id": vendor.vendor_id,
"country_id": "IE",
"city": "Dublin",
"founding_year": 2007,
"green_energy": True,
"lat": 53.4056545,
"lon": -6.224503,
},
{
"region_id": "eu-west-2",
"name": "Europe (London)",
"aliases": ["EU (London)"],
"vendor_id": vendor.vendor_id,
"country_id": "GB",
"city": "London",
"founding_year": 2016,
"green_energy": True,
"lat": 51.5085036,
"lon": -0.0609266,
},
{
"region_id": "eu-west-3",
"name": "Europe (Paris)",
"aliases": ["EU (Paris)"],
"vendor_id": vendor.vendor_id,
"country_id": "FR",
"city": "Paris",
"founding_year": 2017,
"green_energy": True,
"lat": 48.6009709,
"lon": 2.2976644,
},
{
"region_id": "il-central-1",
"name": "Israel (Tel Aviv)",
"vendor_id": vendor.vendor_id,
"country_id": "IL",
"city": "Tel Aviv",
"founding_year": 2023,
"green_energy": False,
# approximation based on city location
"lat": 32.0491183,
"lon": 34.7891105,
},
{
"region_id": "me-central-1",
"name": "Middle East (UAE)",
"vendor_id": vendor.vendor_id,
"country_id": "AE",
# NOTE city and state unknown
"display_name": "United Arab Emirates",
"founding_year": 2022,
"green_energy": False,
# approximation based on country
"lat": 25.0647937,
"lon": 55.1363688,
},
{
"region_id": "me-south-1",
"name": "Middle East (Bahrain)",
"vendor_id": vendor.vendor_id,
"country_id": "BH",
# NOTE city and stateunknown
"display_name": "Bahrain",
"founding_year": 2019,
"green_energy": False,
"lat": 25.941298,
"lon": 50.3073907,
},
{
"region_id": "sa-east-1",
"name": "South America (Sao Paulo)",
"vendor_id": vendor.vendor_id,
"country_id": "BR",
"city": "Sao Paulo",
"founding_year": 2011,
"green_energy": False,
"lat": -23.4925798,
"lon": -46.8105593,
},
{
"region_id": "us-east-1",
"name": "US East (N. Virginia)",
"vendor_id": vendor.vendor_id,
"country_id": "US",
"state": "Northern Virgina",
# NOTE city unknown
"founding_year": 2006,
"green_energy": True,
"lat": 38.9940541,
"lon": -77.4524237,
},
{
"region_id": "us-east-2",
"name": "US East (Ohio)",
"vendor_id": vendor.vendor_id,
"country_id": "US",
"state": "Ohio",
# NOTE city unknown
"founding_year": 2016,
"green_energy": True,
"lat": 40.0946354,
"lon": -82.7541337,
},
{
"region_id": "us-west-1",
"name": "US West (N. California)",
"vendor_id": vendor.vendor_id,
"country_id": "US",
"state": "California",
# NOTE city unknown
"founding_year": 2009,
"green_energy": True,
"lat": 37.443680,
"lon": -122.153664,
},
{
"region_id": "us-west-2",
"name": "US West (Oregon)",
"vendor_id": vendor.vendor_id,
"country_id": "US",
"state": "Oregon",
# NOTE city unknown
"founding_year": 2011,
"green_energy": True,
"lat": 45.9174667,
"lon": -119.2684488,
},
]
# add API reference and display names
for region in regions:
region["api_reference"] = region["region_id"]
if region.get("display_name") is None:
display_name_prefix = region.get("city", region.get("state", ""))
region["display_name"] = f"{display_name_prefix} ({region['country_id']})"
# look for undocumented (new) regions in AWS
supported_regions = [d["region_id"] for d in regions]
available_regions = _boto_describe_regions()
for available_region in available_regions:
region_name = available_region["RegionName"]
if "gov" in region_name:
next()
if region_name not in supported_regions:
raise NotImplementedError(f"Unsupported AWS region: {region_name}")
# mark inactive regions
active_regions = [region["RegionName"] for region in available_regions]
for region in regions:
if region["region_id"] in active_regions:
region["status"] = "active"
else:
region["status"] = "inactive"
return regions