Getting Started With PHP & AWS DynamoDB

MySQL has been the most favorite among PHP programmers. In fact this very blog was hosted in LAMP stack (Linux-Apache-MySQL-PHP) a little while go using wordpress. MySQL is still my first choice when it comes to traditional RDBMS (Oracle is kind of too much if its not an enterprise software ). When it comes to NoSQL we often go to Google Appengine/Datastore combination but its a different ball game together as its a platform as a service and datastore can't really be used even from compute engine infrastructure. With recent PHP support of GAE , you can use HTTP interface of Google datastore to create your application , otherwise Google cloud SQL is the solution for deploying wordpress like solution. Published on

Even with Google Cloud's rapidly growing set of cloud service offerings, it has a long way to catch up with AWS's portfolio , especially scale and maturity wise. When it comes to fully manages NoSQL like database on cloud DynamoDB is probably leading the market by a significant margin. IBM's Cloudant , Google's Cloud Datastore has a long way to catch up. I have talked to a lot of cloud consultant recently who tried to sell the later two but an hour into discussion it is revealed that they can't match the scale (Transactions per second mainly ) and price of AWS. Remember inherently all managed databases are expensive, of course remember how much you pay for license , devops and expensive hardware for on premise No-SQL databases like Couchbase, still one goes through upgrade nightmares  and unexpected down times (Tell me about it).

Ok, lets get coding. Most of the reference and example in the internet I found was about Java talking to DynamoDB, of course,  probably majority of DynamoDB users are Java programmers. I had to play around PHP, so thought of jotting down some quick code snippets for future side projects and proof of concepts.

Requirements 

Here is the  Official Tutorial.

Connecting to Database 

 Tough everything is internally REST APIs, you can create a DynamoDB client object which can talk to a specific DynamoDB account.


<?php
$dynamo_config = array(
    'profile' => 'default',
    'region' => 'ap-southeast-1',
    'version' => '2012-08-10',
    //'endpoint'=> 'http://bej-dynamo:8000',
    //'debug' => true
);

define_('DYNAMO_CONFIG', serialize(array($dynamo_config)));
?>