Polyscope - The agent-first dev environment for Laravel

Lumen Dynamodb

nordsoftware/lumen-dynamodb image

Lumen Dynamodb stats

Downloads
3.2K
Stars
10
Open Issues
3
Forks
1

View on GitHub →

DynamoDB module for Lumen framework. Based on https://github.com/baopham/laravel-dynamodb

lumen-dynamodb

Lumen implementation for DynamoDB, based on Bao Pham's laravel-dynamodb.

Prerequisites

To install DynamoDB locally, see Running DynamoDB on Your Computer.

When DynamoDB is set up, start it with java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

You can use the DynamoDB artisan command to manage the DynamoDB at the moment:

php artisan dynamodb:create --config=<TABLE_CONFIGURATION> # To create tables
php artisan dynamodb:delete --config=<TABLE_CONFIGURATION> -y # To delete tables

The table configuration file should return an array of table configurations:

return [
[
'TableName' => 'users',
'AttributeDefinitions' => [
[
'AttributeName' => 'id',
'AttributeType' => 'S',
],
],
'KeySchema' => [
[
'AttributeName' => 'id',
'KeyType' => 'HASH',
],
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 20,
'OnDemand' => false,
],
],
[
'TableName' => 'orders',
'AttributeDefinitions' => [
[
'AttributeName' => 'id',
'AttributeType' => 'S',
],
],
'KeySchema' => [
[
'AttributeName' => 'id',
'KeyType' => 'HASH',
],
],
'ProvisionedThroughput' => [
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 20,
'OnDemand' => false,
],
],
];

If you don't want to use a configuration file, you may as well override the Create/DeleteTablesCommand and put your table definitions in the protected static $tables = [] array to override the tables.

Remember to add the overridden command in your Kernel.php file.

Install

// .env:
DYNAMODB_KEY=<AWS_KEY>
DYNAMODB_SECRET=<AWS_SECRET_KEY>
DYNAMODB_REGION=<AWS_REGION>
DYNAMODB_VERSION=latest
DYNAMODB_LOCAL_ENDPOINT=http://localhost:8000 # Only used for local DynamoDB
 
 
// config/services.php
return [
...
'dynamodb' => [
'key' => env('DYNAMODB_KEY', 'dynamodb_local'),
'secret' => env('DYNAMODB_SECRET', 'secret'),
'region' => env('DYNAMODB_REGION', 'eu-central-1'),
'version' => env('DYNAMODB_VERSION', 'latest'),
'endpoint' => env('DYNAMODB_LOCAL_ENDPOINT', 'http://localhost:8000'),
],
...
];
 
// bootstrap/app.php
...
$app->configure('services');
...
$app->register(Nord\Lumen\DynamoDb\DynamoDBServiceProvider::class);

Usage

Extend all your models from \Nord\Lumen\DynamoDb\Domain\Model\DynamoDbModel

You will need to set the following properties for your model to get the DynamoDbModel to work:

// The keys are defined when creating the table. If you are using only one primary key, set the $primaryKey,
// if using both primaryKey and sortKey, define the $compositeKey.
protected $primaryKey = '<primaryKey>'; // Ignore if using composite key.
protected $compositeKey = ['<primaryKey>', '<sortKey>']; // Ignore if you don't have a composite key.
protected $table = '<table_name>'; // Set the DynamoDB table this model uses
// If using global or local indexes, define the key => indexName values here.
protected $dynamoDbIndexKeys = [
'<globalIndexKey>' => '<globalIndexName>',
'<localIndexKey>' => '<localIndexName>',
];
 
// Set this to be able to mass assign attributes.
protected $fillable = ['email', 'name'];
protected $guarded = ['address'];

Using the models works pretty much in the same way as with Eloquent:

$model = DynamoDbModel::find(1); // Find a model with the primary key 1
// Using where:
$model = DynamoDbModel::where(['email' => 'test@example.com']);
$model->get()->first(); // Returns the first record.
 
$model = new DynamoDbModel(['name' => 'Demo user', 'email' => 'test@example.com']); // Fillable attributes.
$model->setAddress('Teststreet 1'); // Set the guarded attribute.
$model->save();

License

See LICENSE.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Nordsoftware Lumen Dynamodb Related Articles

Laravel 13 Released: PHP 8.3, Attributes, Laravel AI, and a Smoother Upgrade Path image

Laravel 13 Released: PHP 8.3, Attributes, Laravel AI, and a Smoother Upgrade Path

Read article
What We Know About Laravel 13 image

What We Know About Laravel 13

Read article
A DynamoDB Driver for the Laravel Auditing Package image

A DynamoDB Driver for the Laravel Auditing Package

Read article
AWS Developer Center for PHP image

AWS Developer Center for PHP

Read article
Managing Concurrent Requests with Laravel Session Blocking image

Managing Concurrent Requests with Laravel Session Blocking

Read article
A Deep Dive into Sessions in Laravel image

A Deep Dive into Sessions in Laravel

Read article
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic