Amazon DynamoDB PHP CRUD using aws.phar

Hits: 564  

DynamoDB is fully managed, fast and low cost NoSQL database service by Amazon. DynamoDB allows you to offload the administrative operations and scale highly distributed database cluster.

The AWS SDK PHP enables you to use Amazon Web Services like Amazon S3, EC2, RDS, CloudFront, Redshift, DynamoDB, Push Notification Service (SNS) and more from your PHP code project.

AWS.PHAR Now Download aws-php-sdk Packaged Phar from

# wget

You can also download the packaged phar here

Include the SDK in your PHP project require ‘/path/to/aws.phar’;

Now download simple dynamodb-php-wrapper from here


require_once 'aws.phar';
require_once 'DynamoDBWrapper.php'; 

$ddb = new DynamoDBWrapper(array(
    'region' => 'us-east-1'


$result = $ddb->createTable(‘Session’, ‘UserId::N’);
// Create a table ‘Session’, which has a hash key ‘UserId’ as NUMBER.


$result = $ddb->deleteTable(‘Session’);


$item = array(
‘UserId’ => 1,
‘Name’ => ‘Sandeep’,
$result = $ddb->put(‘Session’, $item);


$key = array(
‘UserId’ => 1,
$update = array(
‘Name’ => array(‘PUT’, ‘SVNLabs’)
$result = $ddb->update(‘Session’, $key, $update);


$key = array(
‘UserId’ => 1,
$result = $ddb->delete(‘Session’, $key);


$keyConditions = array(
‘UserId’ => 1,
$result = $ddb->query(‘Session’, $keyConditions);


$filter = null;

$result = $ddb->scan(‘Session’, $filter, 1000);

Scan with between date filter

$filter = array(
‘userType’ => “member”,
“date” => array(“BETWEEN”, array(“2016/08/01″,”2016/08/17”))
$result = $ddb->scan(“Session”, $filter, 1000);

Other Links

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch