AWS Latency Check
This module will take an object of AWS endpoints and run a check against each to find the closest one.
Valid Services Endpoints
This check will run against the /ping
endpoint for the AWS service endpoints provided. For this reason not all AWS services are valid. Valid services include:
- EC2
- SNS
- SQS
- SimpleDB
Methods
constructor(regions [, options])
Used to create an instance of the object.
Arguments
regions
: This whould be an object of each region to check. Key should be the region_id and the value should be the hostname of the region to check. Each region must have a reachable endpoint ofhttp://[hostname]/ping
.options
: Various options for the test.timeout
: The max amount of time that can be passed when checking any one region. This defaults to 4000.
begin()
Called to actually begin the process. After a check has been completed if you wish to re-check you can call this method again.
Emitted Events
check_complete
Fired after the entire check is completed.
Sample Usage
checker;
Arguments
results
: An array of each region results (ordered by lowest latency).
Example
region: 'us-east-1' latency: 123region: 'us-west-1' latency: 187region: 'us-west-2' latency: 198region: 'eu-central-1' latency: 293region: 'ap-northeast-1' latency: 385region: 'sa-east-1' latency: 406region: 'ap-southeast-1' latency: 515region: 'ap-southeast-2' latency: 754region: 'eu-west-1' latency: null
region_complete
After a region is complete.
Sample Usage
checker;
Arguments
progress
: The total percentage completed for the test. This can be used to update a progress bar etc.results
: Object of the region results.
Example
region: 'us-west-1' latency: 162
error
If an error was thrown and the test is stopped.
Sample Usage
checker;
Arguments
err
: The actual error message.
Data Model
Region Results
region
: The region that was tested.latency
: The calculated latency. If there was an error this will benull
.
Example
region: 'us-west-1' latency: 162 status_code: 200
Example Usage
// Require the libraryvar LatencyCheck = ;// Define the regions to check.var regions ="us-east-1": "ec2.us-east-1.amazonaws.com""us-west-1": "ec2.us-west-1.amazonaws.com""ap-southeast-1": "ec2.ap-southeast-1.amazonaws.com""us-west-2": "ec2.us-west-2.amazonaws.com""sa-east-1": "ec2.sa-east-1.amazonaws.com""eu-central-1": "ec2.eu-central-1.amazonaws.com""eu-west-1": "ec2.eu-west-1.amazonaws.com""ap-northeast-1": "ec2.ap-northeast-1.amazonaws.com""ap-southeast-2": "ec2.ap-southeast-2.amazonaws.com";// Create an instance of the objectvar checker = regions;// Call the begin functionchecker;// Listen for the check to complete.checker;// Listen for each region check to complete.checker;// Listen for any errors so we can take the appropriate actionchecker;