Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@benswinburne/closest-aws-region
Advanced tools
Readme
Whilst using lambda@edge your code runs in any one of the available data centres, which is not necessarily true for your data or other services perhaps.
For example, if I'm using Dynamodb global tables and my data exists in
eu-west-1
, us-east-2
and ap-southeast-1
, when my lambda@edge function
runs and sets up a DocumentClient using process.env.AWS_REGION
, the value of
this environment variable may be any of the available AWS regions, perhaps
eu-central-1
.
What this means is that the DocumentClient will fail to retrieve the data as it
attempts to access it from Dynamodb at eu-central-1
as it hasn't been
replicated to that region.
Rather than hard coding or chosing one of the three regions in which I've
stored my data, using this package I can determine which of the regions which
contains my data is closest to process.env.AWS_REGION
(or at least has the
lowest latency).
npm install @benswinburne/closest-aws-region
var closestAWSRegion = require('@benswinburne/closest-aws-region')
import closestAWSRegion from '@benswinburne/closest-aws-region'
// AWS_REGION = eu-central-1
const region = findClosestAWSRegion(process.env.AWS_REGION, {
filters: ['eu-west-1', 'us-east-1', 'ap-southeast-1'],
}); // eu-west-1
closestAWSRegion(to, [options])
Find the closest region to that specified in to
.
Note: If options.filters
is not set, the closest region will always be to
.
default
The default region to select in the event that no region is found. This
defaults to us-east-1
if not set.
filters
Specify the region(s) to limit your search to.
// AWS_REGION = eu-central-1
const region = findClosestAWSRegion(process.env.AWS_REGION, {
filters: ['eu-west-1', 'us-east-1']
}); // eu-west-1
excludeTo
(defaults to false)If for example you are looking for the closest region to eu-west-1, with no
filters applied obviously eu-west-1 is the closted region. By excluding to
,
the return value will be the closest region to eu-west-1 which is not eu-west-1.
data
This option allows for overwriting the static datasource. The format must follow the structure used by cloudping.co.
Note: it's not recommended that a remote datasource is used with lambda@edge because the latency savings by finding the closest region are lost during the roundtrip to an external source
// AWS_REGION = eu-central-1
const response = await fetch('https://api.cloudping.co/averages');
const data = await response.json();
const region = findClosestAWSRegion(process.env.AWS_REGION, {
data: data
});
FAQs
Determines the closest AWS region using average latency between regions
The npm package @benswinburne/closest-aws-region receives a total of 2 weekly downloads. As such, @benswinburne/closest-aws-region popularity was classified as not popular.
We found that @benswinburne/closest-aws-region demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.