Giter VIP home page Giter VIP logo

country-to-aws-region's Introduction

country-to-aws-region

JS library that helps get the closest AWS region from a country code

I have created this library, as I have faced the issue of targeting specific AWS regional endpoints from a Cloudflare Worker. Cloudflare gives me the user's country code in a request header, so I thought I could use this to my advantage.

This simple library helps you translate a country code to the nearest AWS region. It heavily relies on the Regional Data Centers mapping made by the TurnKey Linux team. You can find their repository here. They also published an article about it here.

Installation

npm i country-to-aws-region

Usage

Resolving the nearest AWS region

import { countryToAwsRegion } from 'country-to-aws-region';

const countryCode = 'DE'; // Get the country code from your request headers for example

console.log(countryToAwsRegion(countryCode)); // eu-central-1

Filtering by specific AWS regions

Sometimes, you only want specific AWS regions to be available. In that case, you can pass an array of regions as the second parameter. The function will filter out all regions that do not match.

import { countryToAwsRegion } from 'country-to-aws-region';

const countryCode = 'DE'; // Get the country code from your request headers for example
const regions = ['us-east-2', 'af-south-1'];

console.log(countryToAwsRegion(countryCode, regions)); // us-east-2

Contributing

Updating the data

This repository contains an automatic script that will fetch and parse the data from the TurnKey Linux repository:

npm run update-data

License

This program was created and published by Mehdi Baaboura under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.