Skip to main content

AWS Region Proximity

Print a JSON dictionary where the key is an AWS region code name (us-west-2, eu-central-1, etc.), and the value is a list of regions in order of their physical proximity to the region. You may optionally pass in a list of region code names that you have a copy of the resource in. The results will have the same keys, but the lists will only contain the regions you specified.

Why?

Say you have S3 buckets being cross-region-replicated in us-west-2, eu-central-1, and ap-southeast-1 and you want to put a Cloudfront distribution in front of them. You can use a Lambda@Edge with an Origin Request trigger to change the origin that Cloudfront will pull a resource from. Lambda@Edge has the environment variable AWS_REGION, which will tell you the closest region to where your Lambda is executing. You could then use the list generated by this program to help find the nearest origin that can handle the request.

For example, a request comes in to the DFW edge location. The environment variable AWS_REGION is "us-east-1" (the AWS region associated with the edge location of DFW). You don't have a copy of the resource in us-east-1, but you do have a copy in us-west-2. So that can be the copy you return (as opposed to your copy in eu-central-1 or ap-southeast-1).

Install

pip install aws-region-proximity

Usage

Get the Closest Regions for All Regions

aws-regions

Output:

{
    "us-east-1": [
        "us-east-1",
        "us-east-2",
        "ca-central-1",
        "us-west-2",
        "us-west-1",
        "eu-west-1",
        "eu-west-2",
        "eu-west-3",
        "eu-central-1",
        "eu-north-1",
        "eu-south-1",
        "sa-east-1",
        "ap-northeast-1",
        "me-south-1",
        "cn-north-1",
        "ap-northeast-2",
        "cn-northwest-1",
        "af-south-1",
        "ap-south-1",
        "ap-east-1",
        "ap-southeast-1",
        "ap-southeast-2"
    ],
    ...
    "cn-northwest-1": [
        "cn-northwest-1",
        "cn-north-1",
        "ap-east-1",
        "ap-northeast-2",
        "ap-northeast-1",
        "ap-south-1",
        "ap-southeast-1",
        "me-south-1",
        "eu-north-1",
        "eu-central-1",
        "eu-south-1",
        "eu-west-2",
        "eu-west-3",
        "eu-west-1",
        "ap-southeast-2",
        "us-west-2",
        "us-west-1",
        "ca-central-1",
        "us-east-2",
        "us-east-1",
        "af-south-1",
        "sa-east-1"
    ]
}

Get Closest Specified Regions per Region

For when you have copies in a limited number of regions and just want to see your closest available region given some other region.

aws-regions us-west-2 eu-central-1 ap-southeast-1

Output

{
    "us-east-1": [
        "us-west-2",
        "eu-central-1",
        "ap-southeast-1"
    ],
    "us-east-2": [
        "us-west-2",
        "eu-central-1",
        "ap-southeast-1"
    ],
    "us-west-1": [
        "us-west-2",
        "eu-central-1",
        "ap-southeast-1"
    ],
    "us-west-2": [
        "us-west-2",
        "eu-central-1",
        "ap-southeast-1"
    ],
    "eu-west-1": [
        "eu-central-1",
        "us-west-2",
        "ap-southeast-1"
    ],
    ...
    "cn-north-1": [
        "ap-southeast-1",
        "eu-central-1",
        "us-west-2"
    ],
    "cn-northwest-1": [
        "ap-southeast-1",
        "eu-central-1",
        "us-west-2"
    ]
}

There is still a key for every region, but the list of the closest regions is limited to those specified on the command line.

From Whence Comes This Data?

This Gist: https://gist.github.com/atyachin/a011edf76df66c5aa1eac0cdca412ea9

Instead of geographic coordinates, it'd probably be better if we sorted by actual inter-region latency, like what this table has: https://www.cloudping.co/grid

Put it on the TODO list.

Metadata

Release files for aws-region-proximity 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-region-proximity 0.1.3
File Size Uploaded
aws-region-proximity-0.1.3.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-region-proximity 0.1.3
File Interpreter ABI Platform
aws_region_proximity-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / aws-region-proximity-0.1.3.tar.gz

Download URL aws-region-proximity-0.1.3.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
deb6f4885e414d6237d183718826410b8b06075f0059d1385c6eb868d15b7188
BLAKE2b-256 checksum
How to use checksums
237d1a2555bacb586fc52e087bd458db356255fba795809aa911b395577485aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1

Release files / aws_region_proximity-0.1.3-py3-none-any.whl

Download URL aws_region_proximity-0.1.3-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38fd94cbcb74f9fb9953689cf1b459c96748d4cba80c19cac76a8d92011347fc
BLAKE2b-256 checksum
How to use checksums
7e43168f700c02aacdffc303ae11d4031b9f5b072adae8e2376dd423f4b44264
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page