Book Image

Amazon SimpleDB Developer Guide

Book Image

Amazon SimpleDB Developer Guide

Overview of this book

SimpleDB is a highly scalable, simple-to-use, and inexpensive database in the cloud from Amazon Web Services. But in order to use SimpleDB, you really have to change your mindset. This isn't a traditional relational database; in fact it's not relational at all. For developers who have experience working with relational databases, this may lead to misconceptions as to how SimpleDB works.This practical book aims to address your preconceptions on how SimpleDB will work for you. You will be quickly led through the differences between relational databases and SimpleDB, and the implications of using SimpleDB. Throughout this book, there is an emphasis on demonstrating key concepts with practical examples for Java, PHP, and Python developers.You will be introduced to this massively scalable schema-less key-value data store: what it is, how it works, and why it is such a game-changer. You will then explore the basic functionality offered by SimpleDB including querying, code samples, and a lot more. This book will help you deploy services outside the Amazon cloud and access them from any web host.You will see how SimpleDB gives you the freedom to focus on application development. As you work through this book you will be able to optimize the performance of your applications using parallel operations, caching with memcache, asynchronous operations, and more.
Table of Contents (16 chapters)
Amazon SimpleDB Developer Guide
Credits
Foreword
About the Authors
About the Reviewers
Preface

Preface

SimpleDB is a highly scalable, simple-to-use, and inexpensive database in the cloud from Amazon Web Services. But in order to use SimpleDB, you really have to change your mindset. This isn't a traditional relational database; in fact it's not relational at all. For developers who have experience working with relational databases, this may lead to misconceptions as to how SimpleDB works.

This practical book aims to address your preconceptions on how SimpleDB will work for you. You will be led quickly through the differences between relational databases and SimpleDB, and the implications of using SimpleDB. Throughout this book, there is an emphasis on demonstrating key concepts with practical examples for Java, PHP, and Python developers.

You will be introduced to this massively scalable schema less key-value data store: what it is, how it works, and why it is such a game changer. You will then explore the basic functionality offered by SimpleDB including querying, code samples, and a lot more. This book will help you deploy services outside the Amazon cloud and access them from any web host.

You will see how SimpleDB gives you the freedom to focus on application development. As you work through this book you will be able to optimize the performance of your applications using parallel operations, caching with memcache, asynchronous operations, and more.

Gain in-depth understanding of Amazon SimpleDB with PHP, Java, and Python examples, and run optimized database-backed applications on Amazon's Web Services cloud.

What this book covers

Chapter 1, Getting to Know SimpleDB, explores SimpleDB and the advantages of utilizing it to build web-scale applications.

Chapter 2, Getting Started with SimpleDB, moves on to set up an AWS account, enable SimpleDB service for the account, and install and set up libraries for Java, PHP, and Python. It also illustrates several SimpleDB operations using these libraries.

Chapter 3, SimpleDB versus RDBMS, sheds light on the differences between SimpleDB and a traditional RDBMS, as well as the pros and cons of using SimpleDB as the storage engine in your application.

Chapter 4, The SimpleDB Data Model, takes a detailed look at the SimpleDB data model and different methods for interacting with a domain, its items, and their attributes. It further talks about the domain metadata and reviews the various constraints imposed by SimpleDB on domains, items, and attributes.

Chapter 5, Data Types, discusses the techniques needed for storing different data types in SimpleDB, and explores a technique for storing numbers, Boolean values, and dates. It also teaches you about XML-restricted characters and encoding them using base64 encoding.

Chapter 6, Querying, describes the Select syntax for retrieving results from SimpleDB, and looks at the various operators and how to create predicates that allow you to get back the information you need.

Chapter 7, Storing Data on S3, introduces you to Amazon S3 and its use for storing large files. It practically modifies a sample domain to add additional metadata including a file key that is again used for naming the MP3 file uploaded to S3. The example used in this chapter shows you a simple way to store metadata on SimpleDB while storing associated content that is in the form of binary files on Amazon S3.

Chapter 8, Tuning and Usage Costs, mainly covers the BoxUsage of different SimpleDB queries and the usage costs, along with viewing the usage activity reports.

Chapter 9, Caching, explains memcached and Cache_Lite in detail and their use for caching. It further explores a way you can use memcached with SimpleDB to avoid making unnecessary requests to SimpleDB, that is, by using libraries in Java, PHP, and Python.

Chapter 10, Parallel Processing, analyzes how to utilize multiple threads for running parallel operations against SimpleDB in Java, PHP, and Python in order to speed up processing times and taking advantage of the excellent support for concurrency in SimpleDB.

What you need for this book

To get started with the book and try out the code samples included here you will need following software:

For Python:

For Java:

For the PHP part:

  • PHP with curl support enabled

  • GeSHi (optional): If Generic Syntax Highlighter package is installed the PHP source will be formatted when displayed in the samples available free from http://qbnz.com/highlighter/

Who this book is for

If you are a developer wanting to build scalable, web-based database applications using SimpleDB, then this book is for you. You do not need to know anything about SimpleDB to read and learn from this book, and no basic knowledge is strictly necessary. This guide will help you to start from scratch and build advanced applications.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Typica provides a simple way to access the BoxUsage value along with the RequestId, when you query SimpleDB."

A block of code is set as follows:

public static void main(String[] args) {
SimpleDB sdb = new SimpleDB(awsAccessId, awsSecretKey, true);
try {
ListDomainsResult domainsResult = sdb.listDomains();
System.out.println("RequestID : " + domainsResult.getRequestId());
System.out.println("Box Usage : " + domainsResult.getBoxUsage());
} catch (SDBException ex) {
System.out.println(ex.getMessage());
}
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

"Statement":[{
"Effect":"Allow",
"Action":"sdb:*",
"Resource":"arn:aws:sdb:*:123456789012:domain/user*"
"Condition":{
"IpAddress":{
"aws:SourceIp":"192.168.176.0/24"
}
"Bool":{
"aws:SecureTransport":"true"
}
}
}
]

Any command-line input or output is written as follows:

memcached -p 12312 -d

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Note

Downloading the example code for the book

Visit https://www.packtpub.com//sites/default/files/downloads/7344_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or web site name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.