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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reaatech/idempotency-middleware-adapter-dynamodb

v1.0.1

Published

DynamoDB storage adapter for @reaatech/idempotency-middleware

Readme

@reaatech/idempotency-middleware-adapter-dynamodb

npm version License: MIT CI

AWS DynamoDB storage adapter for @reaatech/idempotency-middleware. Uses conditional writes for distributed locking with TTL-compatible expiresAt attributes, backed by the AWS SDK for JavaScript v3.

Installation

npm install @reaatech/idempotency-middleware-adapter-dynamodb @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb
# or
pnpm add @reaatech/idempotency-middleware-adapter-dynamodb @aws-sdk/client-dynamodb @aws-sdk/util-dynamodb

Feature Overview

  • Conditional write lockingattribute_not_exists(cacheKey) OR expiresAt < :nowSec prevents concurrent lock acquisition across distributed instances
  • TTL-compatible expiresAt — epoch-second attribute compatible with DynamoDB's native TTL feature for automatic record cleanup
  • Client-side TTL enforcement — explicit expiry check on get() as a safety net before DynamoDB TTL scavenging
  • Connectionless — DynamoDB client is ready immediately; connect() and disconnect() are no-ops
  • Implements StorageAdapter — drop-in replacement for any other adapter

Quick Start

import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBAdapter } from '@reaatech/idempotency-middleware-adapter-dynamodb';
import { IdempotencyMiddleware } from '@reaatech/idempotency-middleware';

const client = new DynamoDBClient({ region: 'us-east-1' });
const storage = new DynamoDBAdapter(client, 'idempotency-cache');

const middleware = new IdempotencyMiddleware(storage, { ttl: 3_600_000 });

const result = await middleware.execute(
  'order-456',
  { method: 'POST', path: '/orders', body: { productId: 'abc' } },
  async () => ({ id: 1, status: 'created' }),
);

API Reference

DynamoDBAdapter

import { DynamoDBAdapter } from '@reaatech/idempotency-middleware-adapter-dynamodb';

const adapter = new DynamoDBAdapter(client, 'my-table');

Constructor

| Param | Type | Default | Description | |---|---|---|---| | client | DynamoDBClient | (required) | Configured AWS SDK v3 DynamoDB client | | tableName | string | "idempotency-cache" | The DynamoDB table name |

Table Schema

The adapter expects a table with a partition key cacheKey (type String). Each item stores:

| Attribute | Type | Description | |---|---|---| | cacheKey | S | Partition key — the SHA-256 cache key | | response | (any) | The cached response (serialized) | | createdAt | N | Epoch milliseconds | | ttl | N | TTL in milliseconds | | expiresAt | N | Epoch seconds (createdAt + ttl) — compatible with DynamoDB TTL |

Methods

Implements the full StorageAdapter interface:

| Method | DynamoDB Operation | Description | |---|---|---| | connect() | None | No-op (client is connectionless) | | disconnect() | None | No-op | | get(key) | GetItem with cacheKey partition key | Returns null if missing or expired | | set(key, record) | PutItem with marshalled data + expiresAt | Overwrites existing entries | | delete(key) | DeleteItem with cacheKey partition key | Removes the item | | acquireLock(key, ttl) | PutItem with ConditionExpression | Returns true on success, false on ConditionalCheckFailedException | | releaseLock(key) | DeleteItem on lock:<key> | Removes the lock item | | waitForLock(key, timeout, pollInterval) | GetItem on lock:<key> | Polls until lock disappears, expires, or timeout |

Locking Design

The DynamoDB adapter uses conditional writes for distributed locking:

  1. Acquire: PutItem on lock:<key> with condition attribute_not_exists(cacheKey) OR expiresAt < :nowSec
  2. Release: DeleteItem on lock:<key>
  3. Wait: polls GetItem on lock:<key> — returns when the item is missing or its expiresAt has passed

Expired locks are automatically re-acquirable due to the expiresAt < :nowSec clause in the condition expression.

Usage Patterns

Enabling DynamoDB TTL

Enable TTL on your DynamoDB table pointing to the expiresAt attribute. This lets DynamoDB automatically delete expired items without consuming write capacity:

aws dynamodb update-time-to-live \
  --table-name idempotency-cache \
  --time-to-live-specification "AttributeName=expiresAt,Enabled=true"

IAM Permissions

The adapter requires these DynamoDB actions:

{
  "Effect": "Allow",
  "Action": [
    "dynamodb:GetItem",
    "dynamodb:PutItem",
    "dynamodb:DeleteItem"
  ],
  "Resource": "arn:aws:dynamodb:*:*:table/idempotency-cache"
}

Custom Table Name

const adapter = new DynamoDBAdapter(client, 'prod-idempotency-cache');

Distributed Workers

Multiple Lambda functions or ECS tasks sharing the same DynamoDB table coordinate via conditional writes:

// Lambda A and Lambda B both execute:
const result = await middleware.execute('same-key', ctx, handler);
// Only one handler executes. Both return the same cached result.

Related Packages

License

MIT