npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws-throttle-fixer

v1.1.1

Published

A promise based library to fix throttling issues while sending large number of API requests to AWS

Downloads

23

Readme

AWS Throttle Fixer

AWS limits the number of requests across all APIs within an AWS account, per region. It also limits the burst across all APIs within an AWS account, per Region for some APIs. Due to this restriction many AWS APIs will trigger error responses like ThrottledException, TooManyRequestsException, Throttling and so on. AWS Throttle Fixer internally uses Exponential backoff to remediate this issue and it is a promise based library. This library only works with aws-sdk version 2 and 3.

Table of Contents

Getting Started

How to install

The preferred way to install the AWS-Throttle-Fixer for Node.js is to use the npm package manager for Node.js. Simply type the following into a terminal window:

npm install aws-throttle-fixer

with yarn package manager

yarn add aws-throttle-fixer

Example

aws-sdk version 2.x.x

following example demonstrate calling a describeSnapshots operation with throttle fix enabled in aws-sdk v2.

// aws init
require('dotenv').config()
const AWS = require('aws-sdk')

let awsConfig = {
	region: process.env.REGION,
	accessKeyId: process.env.AWS_ACCESS_KEY_ID,
	secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
}
AWS.config.update(awsConfig)
const ec2Client = new AWS.EC2()

// aws-throttle-fixer init
const ThrottleFixer = require('aws-throttle-fixer')
const TF = new ThrottleFixer()
const tfConfig = {
	retryCount: 24,
	logger: console.log,
	sdkVersion: 2,
	exceptionCodes: ['RequestLimitExceeded'],
}
TF.configure(tfConfig)
const throttleFixFn = TF.throttleFixer()

// aws call is in the function
async function callAwsDescribeSnapshotsAction() {
	try {
		const params = { MaxResults: 10 }
		const snapshotDetails = await throttleFixFn(ec2Client, 'describeSnapshots', params) // calling describeSnapshots operation with throttle fix added
		return snapshotDetails
	} catch (e) {
		console.error(e)
	}
}

callAwsDescribeSnapshotsAction().then()

@aws-sdk version 3.x.x

following example demonstrate calling a describeSnapshots operation with throttle fix enabled in aws-sdk v3.

// aws init
require('dotenv').config()
const { EC2Client, DescribeSnapshotsCommand } = require('@aws-sdk/client-ec2')
const client = new EC2Client({ region: 'us-east-1' })

// aws-throttle-fixer init
const ThrottleFixer = require('aws-throttle-fixer')
const TF = new ThrottleFixer()
const tfConfig = {
	retryCount: 24,
	logger: console.log,
	sdkVersion: 3,
	exceptionCodes: ['RequestLimitExceeded'],
}
TF.configure(tfConfig)
const throttleFixFn = TF.throttleFixer()

// aws call is in the function
async function callAwsDescribeSnapshotsAction() {
	try {
		const params = { MaxResults: 10 }
		const { Snapshots } = await throttleFixFunction(client, DescribeSnapshotsCommand, params)
	} catch (e) {
		console.error(e)
	}
}

callAwsDescribeSnapshotsAction().then()

Usage

In Node.js

To use the AWS-Throttle-Fixer within your nodejs project, import aws-throttle-fixer as you normally would.

ES5 imports

const ThrottleFixer = require('aws-throttle-fixer')

Create the Throttle fixer instance

const TF = new ThrottleFixer()

Configure the options

TF.configure({ retryCount: 24 }) // more available options are listed [here](#configure)

Create a callable throttle method

const throttleFixFn = TF.throttleFixer()

throttleFunction takes 3 arguments. All are required and arguments are different for different sdk version

With sdk version 2

| Sl.no | Argument | Description | Type | Example | | :---- | :--------------- | :-------------------------------------- | :------- | :------------------- | | 1 | AWS Client/Class | The aws class initialed using aws-sdk | class | EC2 | | 2 | Method | The method or action from the class | string | describeSnapshots | | 3 | Parameters | Parameter to pass to the AWS method | object | { MaxResults: 10 } |

With sdk version 3

| Sl.no | Argument | Description | Type | Example | | :---- | :--------------- | :-------------------------------------- | :--------- | :------------------------- | | 1 | AWS Client/Class | The aws class initialed using aws-sdk | class | EC2 | | 2 | Command | The Command imported from sdk | function | DescribeSnapshotsCommand | | 3 | Parameters | Parameter to pass to the AWS method | object | { MaxResults: 10 } |

Call throttleFixFn function with all arguments provided

const response = await throttleFixFn(awsClient, 'awsService', params) // for sdk version 2
const response = await throttleFixFn(awsClient, CommandFromClient, params) // for sdk version 3

Configurations

| API Name | Description | Type | Default | | :------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------- | :------ | | retryCount | Number of retries to perform in case of throttle error | number | 10 | | logger | A function that can be used for logging the debug logs about throttling | function | null | | exceptionCodes | What all error codes need to be considered as Throttled? by default following error codes are considered to be throttling ThrottledException, TooManyRequestsException, Throttling | string[] | [] | | ignoreRetryState | If set to true, will ignore the retry state retryable in aws api response. Available only when using sdkVersion with value 2 | boolean | false | | sdkVersion | AWS SDK version number, provide only major version | number | 2 | | additionalWaitTime | API will wait for the specified time before making any other actions, (time in milliseconds) | number | 0 |

Error Codes

  1. UnknownClientException - this exception will raise if no aws client is provided to the throttleFixFn function
  2. UnknownModuleException - this exception will raise if no module name is provided to the throttleFixFn function (only when using sdkVersion 2)
  3. UnknownSdkVersionException - this exception will raise if sdkVersion provided to the configuration is incorrect
  4. UnknownCommandException - this exception will raise if command provided to the throttleFixFn configuration is incorrect (only when using sdkVersion 3)
  5. others - All other errors are thrown from the method