Laravel
Integrations · Laravel
Laravel can keep its cache, atomic locks, sessions and failed jobs in DynamoDB. Dynoxide runs all four locally, so development and tests need neither AWS nor amazon/dynamodb-local. For PHP tests outside Laravel, the Composer package starts Dynoxide from PHPUnit.
Laravel's own DynamoDB integration tests pass against it: on 11 November 2026, tests/Integration/Cache/DynamoDbStoreTest.php, tests/Integration/Queue/DynamoBatchTest.php and tests/Integration/Queue/DynamoBatchTestWithTTL.php from laravel/framework (commit c33d357) ran against Dynoxide 1.6.0, with the environment Laravel's own CI uses for amazon/dynamodb-local: 18 tests, all passing.
With the package
On Laravel 12 or 13, nubo-db/dynoxide-laravel does the setup for you. It reads your app's config, so custom table names and key attributes need nothing extra.
composer require --dev nubo-db/dynoxide-laravel
For tests, put its trait on your base test case:
use Dynoxide\Laravel\Testing\UsesDynoxide;
abstract class TestCase extends BaseTestCase
{
use UsesDynoxide;
}
The trait starts Dynoxide once per test process, points the DynamoDB cache, rate limiter, sessions and failed jobs at it, creates the tables your config names and empties them after each test. It doesn't change which drivers the app uses, so in phpunit.xml change the array lines Laravel generates, and add the failed-job one if failed jobs go to DynamoDB too:
<env name="CACHE_STORE" value="dynamodb"/>
<env name="SESSION_DRIVER" value="dynamodb"/>
<env name="QUEUE_FAILED_DRIVER" value="dynamodb"/>
The server listens on a free port. From package 1.1.0, port in dynoxideOptions() fixes it, for when something outside the tests needs to know it in advance. Set it from an environment variable that exists before the app boots, from the shell, CI or an <env> in phpunit.xml, not from .env: dynoxideOptions() is first called before Laravel loads .env. An environment variable is a string, so cast it:
protected function dynoxideOptions(): array
{
return ['port' => (int) getenv('DYNOXIDE_TEST_PORT')];
}
If the port is taken, the tests fail with a StartException that names it, whose previous exception is the core package's PortInUseException. Under ParaTest, and in a #[RunInSeparateProcess] test, a non-zero port throws a ConfigException, since each of those processes starts a server of its own.
For local development, php artisan dynoxide:serve runs Dynoxide on port 8800 with the same tables already created. With package 1.1.0 and Dynoxide 1.8.0 or later, a taken port exits 4, and the message names the port and says how to move it: --port, DYNOXIDE_PORT in .env or dynoxide.port in config/dynoxide.php, with DYNAMODB_ENDPOINT set to match. The package README covers the .env settings, ParaTest, and what to watch for when the app reads the cache in boot().
Without the package
On Laravel 11 and earlier, or to keep the setup in your own hands, Dynoxide can run beside the app and Laravel can point at it with configuration alone.
The tables
Laravel expects two tables, and Dynoxide can create them as it starts. Save this as dynamodb-tables.json beside your docker-compose.yml:
[
{
"Table": {
"TableName": "cache",
"KeySchema": [{ "AttributeName": "key", "KeyType": "HASH" }],
"AttributeDefinitions": [{ "AttributeName": "key", "AttributeType": "S" }],
"BillingModeSummary": { "BillingMode": "PAY_PER_REQUEST" }
}
},
{
"Table": {
"TableName": "failed_jobs",
"KeySchema": [
{ "AttributeName": "application", "KeyType": "HASH" },
{ "AttributeName": "uuid", "KeyType": "RANGE" }
],
"AttributeDefinitions": [
{ "AttributeName": "application", "AttributeType": "S" },
{ "AttributeName": "uuid", "AttributeType": "S" }
],
"BillingModeSummary": { "BillingMode": "PAY_PER_REQUEST" }
}
}
]
cache holds the cache, the locks and, with the dynamodb session driver, the sessions. You only need failed_jobs if failed jobs go to DynamoDB too. Both names are Laravel's defaults.
Run Dynoxide
With Docker Compose:
services:
dynamodb:
image: ghcr.io/nubo-db/dynoxide
command: serve --host 0.0.0.0 --port 8000 --schema /data/dynamodb-tables.json
ports:
- "8000:8000"
volumes:
- ./dynamodb-tables.json:/data/dynamodb-tables.json:ro
Or without Docker, from the project directory:
npx dynoxide --port 8000 --schema dynamodb-tables.json
Either way the data lives in memory and goes when Dynoxide stops, which is what a test suite wants. To keep it, add --db-path; see Docker.
Point Laravel at it
In .env:
CACHE_STORE=dynamodb
DYNAMODB_ENDPOINT=http://localhost:8000
AWS_ACCESS_KEY_ID=dynoxide
AWS_SECRET_ACCESS_KEY=dynoxide
AWS_DEFAULT_REGION=us-east-1
On Laravel 10 and earlier the cache variable is CACHE_DRIVER, not CACHE_STORE. Use http://dynamodb:8000 instead when the app runs in the same Compose project.
For tests, Laravel's phpunit.xml already sets CACHE_STORE and SESSION_DRIVER to array, and PHPUnit keeps the first value it sees, so change those lines rather than adding new ones. Any non-empty credentials work: Dynoxide checks they're there and never checks the signature.
config/cache.php already reads DYNAMODB_ENDPOINT for its dynamodb store, so the cache and locks need nothing more.
Sessions
Set SESSION_DRIVER=dynamodb. Sessions then go through the dynamodb cache store and its table.
Failed jobs
Set QUEUE_FAILED_DRIVER=dynamodb. Unlike the cache store, the failed entry in Laravel's generated config/queue.php has no credentials, region or endpoint, so add them:
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
'database' => env('DB_CONNECTION', 'sqlite'),
'table' => 'failed_jobs',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
'endpoint' => env('DYNAMODB_ENDPOINT'),
],
In GitHub Actions
Swap the image in the service container:
services:
dynamodb:
image: ghcr.io/nubo-db/dynoxide
ports:
- 8000:8000
A service container can't be given --schema, so create the tables from the test suite instead. A base test case can do it once per run, ignoring the error when the table is already there:
use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Exception\DynamoDbException;
private static bool $tablesCreated = false;
protected function setUp(): void
{
parent::setUp();
if (self::$tablesCreated) {
return;
}
self::$tablesCreated = true;
$client = new DynamoDbClient([
'region' => 'us-east-1',
'version' => 'latest',
'endpoint' => env('DYNAMODB_ENDPOINT'),
'credentials' => ['key' => 'dynoxide', 'secret' => 'dynoxide'],
]);
try {
$client->createTable([
'TableName' => 'cache',
'KeySchema' => [['AttributeName' => 'key', 'KeyType' => 'HASH']],
'AttributeDefinitions' => [['AttributeName' => 'key', 'AttributeType' => 'S']],
'BillingMode' => 'PAY_PER_REQUEST',
]);
} catch (DynamoDbException $e) {
if ($e->getAwsErrorCode() !== 'ResourceInUseException') {
throw $e;
}
}
}
Add failed_jobs the same way if you use it, with application as the partition key and uuid as the sort key.