# casbin-dynamodb-adapter

> Casbin DynamoDB Adapter

Latest version **0.5.0** (published 2025-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install casbin-dynamodb-adapter
pnpm add casbin-dynamodb-adapter
yarn add casbin-dynamodb-adapter
bun add casbin-dynamodb-adapter
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2025-10-09 |
| First published | 2020-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.0.0 |
| Dependencies | 1 |
| Unpacked size | 25.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | fospitia@gmail.com |
| Maintainers | fospitia |

## Links

- npm: https://www.npmjs.com/package/casbin-dynamodb-adapter
- Repository: https://github.com/fospitia/casbin-dynamodb-adapter
- Homepage: https://github.com/fospitia/casbin-dynamodb-adapter#readme
- Issues: https://github.com/fospitia/casbin-dynamodb-adapter/issues
- npm.io page: https://npm.io/package/casbin-dynamodb-adapter

## Dependencies (1)

- [casbin](https://npm.io/package/casbin.md) ^5.38.0

## Recent versions

- 0.5.0 (latest) — 2025-10-09
- 0.4.1 — 2022-09-22
- 0.4.0 — 2022-08-15
- 0.3.2 — 2021-08-16
- 0.3.0 — 2021-03-31
- 0.2.1 — 2020-12-02
- 0.2.0 — 2020-11-27
- 0.1.1 — 2020-11-27
- 0.1.0 — 2020-11-12

## README

# casbin-dynamodb-adapter

DynamoDB adapter for Casbin https://github.com/casbin/node-casbin

Based on [casbin-couchbase-adapter](https://github.com/MarkMYoung/casbin-couchbase-adapter).

## Installation

npm install casbin-dynamodb-adapter

## Changes in version 0.5.x

- **AWS SDK v3 Support**: Full compatibility with AWS SDK v3
- **Backward Compatibility**: Still supports AWS SDK v2
- **Enhanced Configuration**: Built-in client creation from config
- **LocalStack Support**: Easy endpoint configuration for local development

## Changes in version 0.4.x

- Change in CasbinDynamoDBAdapter class import
- New CasbinDynamoDBFilteredAdapter class based on DefaultFilteredAdapter class

## AWS SDK v3 Example (Recommended)

```js
const Casbin = require('casbin');
const { CasbinDynamoDBAdapter } = require('casbin-dynamodb-adapter');

(async () => {
  try {
    // Create adapter with configuration
    const adapter = await CasbinDynamoDBAdapter.newAdapter({
      region: 'us-east-1',
      tableName: 'casbin-rules'
      // Uses default: hashKey: 'id' (MD5 hash primary key)
      // AWS SDK uses IAM roles automatically (ECS, EC2, Lambda)
      // Credentials only needed for LocalStack:
      // endpoint: 'http://localhost:4566',
      // credentials: { accessKeyId: 'test', secretAccessKey: 'test' }
    });

    const enforcer = await Casbin.newEnforcer('model.conf', adapter);

    // Load policies from the database
    await enforcer.loadPolicy();

    // Add a policy
    await enforcer.addPolicy('alice', 'data1', 'read');

    // Check permissions
    const isMatched = enforcer.enforce('alice', 'data1', 'read');
    console.log(isMatched);

    await enforcer.removePolicy('alice', 'data1', 'read');

    // Save policies back to the database
    await enforcer.savePolicy();
  } catch (e) {
    console.error(e);
  }
})();
```

## AWS SDK v2 Example (Legacy)

```js
const Casbin = require('casbin');
const { CasbinDynamoDBAdapter } = require('casbin-dynamodb-adapter');
const AWS = require('aws-sdk');

const client = new AWS.DynamoDB.DocumentClient();

(async () => {
  try {
    const opts = {
      tableName: 'casbin-rules',
      hashKey: 'id'
    };
    const enforcer = await Casbin.newEnforcer('model.conf', new CasbinDynamoDBAdapter(client, opts));

    // Load policies from the database
    await enforcer.loadPolicy();

    // Add a policy
    await enforcer.addPolicy('alice', 'data1', 'read');

    // Check permissions
    const isMatched = enforcer.enforce('alice', 'data1', 'read');
    console.log(isMatched);

    await enforcer.removePolicy('alice', 'data1', 'read');

    // Save policies back to the database
    await enforcer.savePolicy();
  } catch (e) {
    console.error(e);
  }
})();
```

---
_Source: https://npm.io/package/casbin-dynamodb-adapter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
