Amazon Web Services: A Brief Introduction Using PHP

Caching

Our simple example above left a few loose ends - caching and error checking. It's highly recommended that you cache your AWS results. There's a performance benefit, and you don't want to risk breaking Amazon's "1 query per second" rule, especially when you get popular with Google. There's an excellent PEAR packaged called Cache Lite that will help us out. It is small, stable, very fast, and easy to setup. Follow the instructions, but basically all you have to do is save the Cache Lite files to a directory above your web root and create a separate directory where the actual cached files will be stored.

Download Cache Lite.

You could also use phpCache, a full tutorial on how to implement it can be found here.

Error Checking

Finally, we want to check for two basic errors:

  1. AWS is down.
  2. AWS returned XML, but your search did not return any results.

Unfortunately, you can't expect 99% uptime with AWS. I know, I said AWS runs on autopilot, but there are times when the service isn't as responsive as you'd hope. Test to see if AWS is down by searching for "xml" in the XML document. (Don't search for an empty string because sometimes AWS returns a generic error message.) For a valid call to AWS that returns no products, such as a bad keyword search, look for the tag in the XML. If you get the ErrorMsg, no results were found.

Destination-USA

Destination-USA is ready to launch! The function to build the XML link to AWS is contained in an include file for portability. Notice in the function file the three arrays which store common attributes used in the XML link. Observe which attributes are passed via the querystring for each page. The caching and error checking have been implemented. As you click around the site, you may notice some books are missing data. This is common with AWS, not every product has an official description or customer reviews. There is a data error check example in the Product Page (product.php) for the tag. Include the error check for every piece of data if you want to be thorough.

Below, you can launch the site and view the source of each page. Each link opens a new window:

Final Thoughts

There are a number of improvements that could be made to Destination-USA. The URLs could become search engine friendly. You could read up in the Developer's Kit and create a local shopping cart. A more ambitious project would be to download the AWS data into a local database, that way you would have total layout freedom (you wouldn't be stuck on the 10 item limit) and have improved protection from AWS outages. The possibilities are endless.

AWS Resources & Examples
  • Amazon's Developer's Kit. To explore all the functionality available through AWS, read the official documentation.
  • http://www.BrowseNodes.com I bet you're wondering, is there an automated way to get BrowseNodes? Not from Amazon, they don't provide a list of BrowseNodes. The above site may be a huge help for the AWS developer on the BrowseNode prowl.
  • PCBunk.net An outstanding AWS electronics site. Notice the shopping cart.
  • Inlibris Bookstore A nice AWS bookstore