13 Sep

DynamoDB session driver for Laravel 5


In this tutorial you will learn how to you can easily create DynamoDB session driver for Laravel 5 to store user sessions in Amazon’s DynamoDB.

Install Aws Service Provider for Laravel

First you need to install AWS Service Provider in your project. Add the following line to your composer.json file.

Then run a composer update

Find the providers key in your config/app.php and register the AWS Service Provider.

Find the aliases key in your config/app.php and add the AWS facade alias.

To customise the configuration file, publish the package configuration using Artisan.

Update your settings in the generated app/config/aws.php configuration file.

Now we need to setup a new session driver.

Create DynamoDb Service Provider

Above artisan command will add a new service provider app/Providers/DynamoSessionServiceProvider.php 

Now, replace the content of the new provider with the following code:

Register Service Provider

Add the following entry to providers array in config/app.php file.

Update Sessions config

Now you need to make following changes to the app/sessions.php file.

Region is the Aws region in which you have setup DynamoDb. You can also set the session driver in .env file.

That’s it. Now, your Laravel application sessions will be stored in DynamoDb.

Note: Make sure you set correct table name(one you created in Amazon DynamoDb console) in your app/sessions.php  file and also make sure your IAM user has full permissions to access DynamoDB.

Hope you found this article helpful. If you have any questions, please ask in comments.


The following two tabs change content below.

Vineet Garg

Sr. Web Developer at GuestHouser
I am passionate about technology and web development.

Latest posts by Vineet Garg (see all)