PHPackages                             pixelandtonic/yii2-dynamodb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. pixelandtonic/yii2-dynamodb

Abandoned → [craftcms/yii2-dynamodb](/?search=craftcms%2Fyii2-dynamodb)Library[Caching](/categories/caching)

pixelandtonic/yii2-dynamodb
===========================

Yii2 implementation of a cache, session, and queue driver for DynamoDB

2.0.1(3y ago)31.5k1[1 issues](https://github.com/craftcms/yii2-dynamodb/issues)[1 PRs](https://github.com/craftcms/yii2-dynamodb/pulls)MITPHPCI passing

Since Nov 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/craftcms/yii2-dynamodb)[ Packagist](https://packagist.org/packages/pixelandtonic/yii2-dynamodb)[ RSS](/packages/pixelandtonic-yii2-dynamodb/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (7)Versions (8)Used By (0)

DynamoDB Cache, Session, and Queue for Yii 2
============================================

[](#dynamodb-cache-session-and-queue-for-yii-2)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3002b4096234e0690ac17f27c585c48feb29bc41e75b4e8b9d0fb331fd9322b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372616674636d732f796969322d64796e616d6f64622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/craftcms/yii2-dynamodb)[![Total Downloads](https://camo.githubusercontent.com/ce236d8cc6d1ae5bdbe5e73a99241c71f8f73942d3a9599077508748476a561a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6372616674636d732f796969322d64796e616d6f64622e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/craftcms/yii2-dynamodb)[![GitHub Tests Action Status](https://camo.githubusercontent.com/12d7cc21aa60e24097ccec16bd032a62f49ef426e9f1efdc0a530cf40bfc822a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6372616674636d732f796969322d64796e616d6f64622f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/craftcms/yii2-dynamodb/actions?query=workflow%3Aci+branch%3Amain)

Easily use DynamoDB as a [cache](https://www.yiiframework.com/doc/guide/2.0/en/caching-overview), [session](https://www.yiiframework.com/doc/guide/2.0/en/runtime-sessions-cookies), or [queue](https://github.com/yiisoft/yii2-queue) using this library in your Yii2 or Craft CMS projects.

> Note: currently Craft supports Yii2 Queue version 2.3.0 so this package is based on version 2.3.0 of yii2-queue.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require craftcms/yii2-dynamodb
```

Usage
-----

[](#usage)

This package provides three Yii components for DynamoDB: cache, session, and queue.

### Cache Component

[](#cache-component)

#### Create DynamoDB Cache Table

[](#create-dynamodb-cache-table)

Since DynamoDB is a NoSQL database, the only key you have to specify is the primary key. You can use the following AWS CLI command to generate a table for the cache.

```
aws dynamodb create-table --table-name=my-app-cache-table \
    --attribute-definitions=AttributeName=id,AttributeType=S \
    --key-schema=AttributeName=id,KeyType=HASH \
    --billing-mode=PAY_PER_REQUEST
```

> Note: Since the ID can contain more than numbers, it needs to be specified as a string in DynamoDB.

#### Configure Cache Component

[](#configure-cache-component)

In your `app.php`, configure the `cache` component to use the driver.

```
use craftcms\dynamodb\DynamoDbCache;

return [
    'bootstrap' => [
        'cache',
    ],
    'components' => [
        'cache' => [
            'class' => DynamoDbCache::class,
            'dataAttribute' => 'data', // optional: defaults to data
            'dynamoDb' => [
                'table' => 'my-app-cache-table',
                'partitionKeyAttribute' => 'id', // optional: defaults to 'PK'
                'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
                'region' => '', // optional: defaults to AWS_REGION env var
                'ttl' => 60*60*24, // optional: number of seconds until items are considered expired
                'ttlAttribute' => 'expires' // optional: defaults to 'TTL'
                'credentials' => [
                    'key' => '', // optional: defaults to AWS_ACCESS_KEY_ID env var
                    'secret' => '', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
                ],
            ],
        ],
    ],
];
```

### Session Component

[](#session-component)

#### Create DynamoDB Session Table

[](#create-dynamodb-session-table)

Since DynamoDB is a NoSQL database, the only key you have to specify is the primary key. You can use the following AWS CLI command to generate a table for the session.

```
aws dynamodb create-table --table-name=my-app-session-table \
    --attribute-definitions=AttributeName=id,AttributeType=S \
    --key-schema=AttributeName=id,KeyType=HASH \
    --billing-mode=PAY_PER_REQUEST
```

> Note: Since the ID can contain more than numbers, it needs to be specified as a string in DynamoDB.

#### Configure Session Component

[](#configure-session-component)

In your `app.php`, configure the `session` component to use the driver.

```
use craftcms\dynamodb\DynamoDbSession;

return [
    'bootstrap' => [
        'session',
    ],
    'components' => [
        'session' => [
            'class' => DynamoDbSession::class,
            'dataAttribute' => 'data', // optional: defaults to data
            'dynamoDb' => [
                'table' => 'my-app-session-table',
                'partitionKeyAttribute' => 'id', // optional: defaults to 'PK'
                'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
                'region' => '', // optional: defaults to AWS_REGION env var
                'ttl' => 60*60*24, // optional: number of seconds until items are considered expired
                'ttlAttribute' => 'expires' // optional: defaults to 'TTL'
                'credentials' => [
                    'key' => '', // optional: defaults to AWS_ACCESS_KEY_ID env var
                    'secret' => '', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
                ],
            ],
        ],
    ],
];
```

### Queue Component

[](#queue-component)

#### Create DynamoDB Queue Table

[](#create-dynamodb-queue-table)

Since DynamoDB is a NoSQL database, the only key you have to specify is the primary key. You can use the following AWS CLI command to generate a table for the queue.

```
aws dynamodb create-table --table-name=my-app-queue-table \
    --attribute-definitions=AttributeName=id,AttributeType=S \
    --key-schema=AttributeName=id,KeyType=HASH \
    --billing-mode=PAY_PER_REQUEST
```

> Note: Since the ID can contain more than numbers, it needs to be specified as a string in DynamoDB.

#### Configure Queue Component

[](#configure-queue-component)

In your `app.php`, configure the `queue` component to use the driver.

```
use craftcms\dynamodb\DynamoDbQueue;

return [
    'bootstrap' => [
        'queue',
    ],
    'components' => [
        'queue' => [
            'class' => DynamoDbQueue::class,
            'dynamoDb' => [
                'table' => 'my-app-queue-table',
                'partitionKeyAttribute' => 'id', // optional: defaults to 'PK'
                'endpoint' => 'http://localhost:8000', // optional: used for local or when using DAX
                'region' => '', // optional: defaults to AWS_REGION env var
                'ttl' => 60*60*24, // optional: number of seconds until items are considered expired
                'ttlAttribute' => 'expires' // optional: defaults to 'TTL'
                'credentials' => [
                    'key' => '', // optional: defaults to AWS_ACCESS_KEY_ID env var
                    'secret' => '', // optional: defaults to AWS_SECRET_ACCESS_KEY env var
                ],
            ],
        ],
    ],
];
```

### Testing

[](#testing)

Tests run against local DynamoDB tables using Docker. To run tests, you must run the following:

1. Ensure Docker is running
2. Start the DynamoDB container in the `docker-compose.yaml` with `docker-compose up -d`
3. Create the DynamoDB tables for the [cache](#create-dynamodb-cache-table), [session](#create-dynamodb-session-table), and [queue](#create-dynamodb-queue-table)
4. Run the test suite with `vendor/bin/phpunit --testdox`

To make the setup and testing easier, you can run the following Composer scripts:

1. `composer run setup`
2. `composer run test`

Credits
-------

[](#credits)

- [Jason McCallister](https://github.com/jasonmccallister)
- [Tim Kelty](https://github.com/timkelty)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 51.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~427 days

Total

3

Last Release

1161d ago

Major Versions

v1.0.0 → 2.0.02022-04-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ccdf8b493035de2343c55bd889513e3af5c04d5823482a2b186ad16adb1c3e3?d=identicon)[brandonkelly](/maintainers/brandonkelly)

---

Top Contributors

[![jasonmccallister](https://avatars.githubusercontent.com/u/5354908?v=4)](https://github.com/jasonmccallister "jasonmccallister (80 commits)")[![timkelty](https://avatars.githubusercontent.com/u/18329?v=4)](https://github.com/timkelty "timkelty (56 commits)")[![angrybrad](https://avatars.githubusercontent.com/u/61869?v=4)](https://github.com/angrybrad "angrybrad (20 commits)")

---

Tags

dynamodbcachequeuesessionyii2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pixelandtonic-yii2-dynamodb/health.svg)

```
[![Health](https://phpackages.com/badges/pixelandtonic-yii2-dynamodb/health.svg)](https://phpackages.com/packages/pixelandtonic-yii2-dynamodb)
```

###  Alternatives

[devgroup/yii2-tag-dependency-helper

Helper for unifying cache tag names with invalidation support in yii2

34507.4k7](/packages/devgroup-yii2-tag-dependency-helper)[undefinedor/yii2-cached-active-record

The cached activeRecord for the Yii2 framework

102.6k](/packages/undefinedor-yii2-cached-active-record)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
