AWS CDK Region Info

2.250.0 · active · verified Thu Apr 16

The `aws-cdk-region-info` library provides a comprehensive directory of AWS region-specific information, such as service principal names for IAM policies, S3 static website endpoints, and other essential regional facts. As a core component of the AWS Cloud Development Kit (CDK) v2, it enables CDK applications to dynamically adapt to regional differences. The library is actively maintained and receives frequent updates, typically alongside new AWS CDK releases, with the current version being 2.250.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to retrieve standard region information using `RegionInfo.get()` and its attributes, as well as how to use `Fact.find()` for specific facts. It also includes an example of how to register custom region facts for new or overridden data.

import os
from aws_cdk import region_info

# Get information for a specific region
us_east_1_info = region_info.RegionInfo.get("us-east-1")
print(f"S3 Static Website Endpoint for us-east-1: {us_east_1_info.s3_static_website_endpoint}")

# Get a service principal for a region
s3_service_principal = us_east_1_info.service_principal("s3.amazonaws.com")
print(f"S3 Service Principal for us-east-1: {s3_service_principal}")

# Find a specific fact for a region using Fact.find()
# Example: Get the domain suffix for a China region
cn_north_1_domain_suffix = region_info.Fact.find("cn-north-1", region_info.FactName.DOMAIN_SUFFIX)
print(f"Domain Suffix for cn-north-1: {cn_north_1_domain_suffix}")

# Override or add a custom fact (e.g., for a new or hypothetical region)
# This is for demonstration; normally you'd implement IFact
class MyCustomFact:
    def __init__(self, region, name, value):
        self.region = region
        self.name = name
        self.value = value

@region_info.jsii.implements(region_info.IFact)
class CustomEndpointFact(MyCustomFact):
    pass

custom_region = "bermuda-triangle-1"
custom_endpoint_fact = CustomEndpointFact(
    region=custom_region,
    name=region_info.FactName.S3_STATIC_WEBSITE_ENDPOINT,
    value="s3-website.bermuda-triangle-1.nowhere.com"
)
region_info.Fact.register(custom_endpoint_fact)

# Retrieve the custom fact
retrieved_custom_endpoint = region_info.RegionInfo.get(custom_region).s3_static_website_endpoint
print(f"Custom S3 Static Website Endpoint for {custom_region}: {retrieved_custom_endpoint}")

view raw JSON →