Integrating Tarzan Amazon Web Services PHP Toolkit as a CodeIgniter Library
At OnePage, we are building our startup based on agility using lean startup techniques and customer development. Some of our influencers are Steve Blank, Eric Ries and Timothy Fitz.
Into this goal comes Amazon Web Services, which enables us to do without the need of a sysadmin, saving costs and improving speeding time to deployment. It also helps us with scalability and flexibility.
The great thing about right now is that there are so many great people out there coding things and making them open source. So when we chose to make use of Amazon Web Services, it did not take us long to find the fantastic Tarzan Amazon Web Services PHP Toolkit (which I think will soon be renamed to CloudFusion). This toolkit makes using the AWS API for S3 and SimpleDB amongst other services much easier.
In addition to making use of Amazon Web Services to leverage cloud computing, we also use CodeIgniter as our PHP Framework as choice. I won't get into the debate of why we do and why we chose it over other frameworks, as that is a topic for another post, but I'll go with their description: it "helps you write kick-ass PHP programs".
Today I came across a post in the Tarzan Google Group where someone was asking how the Tarzaon toolkit can be integrated as a CodeIgniter library. We've done this at OnePage so I thought I'd share. Credit for this goes to Dan, our lead developer :)
It's quite simple really:
- First, put the contents of Tarzan in a directory titled "tarzan" in your Application Libraries directory in CodeIgniter.
- Add the required constants from the config-sample.inc.php file in tarzan to the CodeIgniter config/constants.php file to set up your AWS Access Identifiers.
- Write a CodeIgniter Library to utilise the Tarzan toolkit which you now have placed in the libraries directory.
- Use Tarzan AWS Toolkit as you would normally.
Code sample for step 3 (File named "Aws.php" placed in application/libraries):
<?php
if (!defined('BASEPATH')) {exit('No direct script access allowed');}
class AWS
{
function __construct($class = NULL)
{
ini_set('include_path', ini_get('include_path').';'.PATH_SEPARATOR . APPPATH . 'libraries/tarzan');
require_once('tarzan.class.php');
}
}
Code sample for Step 4:
$this->load->library("aws");
$sdb = new AmazonSDB();
$del = $sdb->delete_attributes("your_domain", $itemName);
$success = ($del->isOk());
I hope that helps someone!
