Skip to content

THOUSAND-SKY/graphql-rate-limit-dynamodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-rate-limit-dynamodb

AWS Dynamodb backend for graphql-rate-limit package.

Usage

// sdk v2
import { DocumentClient } from 'aws-sdk/clients/dynamodb';
import { DynamoStoreV2 } from 'graphql-rate-limit-dynamodb';
// sdk v3
// import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
// import { DynamoStoreV3 } from "graphql-rate-limit-dynamodb";

const UserRateLimited = createRateLimitRule({
  identifyContext: ctx => ctx.user.id,
  store: new DynamoStoreV2(new DocumentClient(getOptionsSomehow()), {
    tableName: 'my-table',
    pk: 'pk',
    sk: { sk: 'sk', value: 'any-sane-static-value-for-sk' }, // If table uses sort key.
    ttlField: "ttl-field's-name", // ttl field is recommended, else there will lots of rows.
  }),
});

Caveats

I messed up the dev setup, it seems to be pulling both aws-sdk-v2 and aws-sdk-v2 into the bundle 😞.