Amazon SimpIeDB Developer Guide Scale your application's database on the cloud using Amazon SimpIeDB Prabhakar Chaganti Rich Helms f...-. I enterprise 1 3 1 1 I ; i,acaessiouci' cxperhs;;- diotiilea PUBLISHING - BIRMINGHAM MUMBAI
Firefox Table of Contents Preface 1 Chapter 1: Getting to Know SimpleDB 7 Experimenting with SimpleDB 9 How does SimpleDB work? 10 Domain 10 Item 10 Attributes 11 Values 11 How do I interact with SimpleDB? 12 How is SimpleDB priced? 13 Free tier 14 Why should I use SimpleDB? 14 Make your applications simpler to architect 14 Build flexibility into your applications 15 Create high-performance web applications 15 Take advantage of lower costs 15 Scale your applications on demand 15 Architect for the cloud 15 Summary 16 Chapter 2: Getting Started with SimpleDB 17 Creating an AWS account 17 Enabling SimpleDB service for AWS account 18 Query API and authentication 21 SimpleDB libraries 22 SDBtool plugin 23 Sample outline performing basic operations 27 Basic operations with Java 27
consistent Table of Contents Exploring SimpleDB with Java 28 Creating a domain with Java 29 Listing domains with Java 29 Manipulating items with Java 29 Deleting a domain with Java 31 Basic operations with PHP 31 Exploring SimpleDB with PHP 32 Creating a domain with PHP 35 Listing domains with PHP 35 Manipulating items with PHP 35 Deleting a domain with PHP 37 Basic operations with Python 37 Introducing boto 38 Exploring SimpleDB with Python 39 Creating a domain with Python 40 Retrieving a domain with Python 40 Creating items with Python 40 Summary 42 Chapter 3: SimpleDB versus RDBMS 43 No normalization 44 No joins 47 No schemas 48 Simpler SQL 51 Only strings 51 Eventual consistency 52 Flash: February 24, 2010 read added 53 Scalability 53 Low maintenance 54 Advantages of the SimpleDB model 54 Disadvantages of the SimpleDB model 55 Summary 55 Chapter 4: The SimpleDB Data Model 57 Domains 58 Domains with Java 58 Domains with PHP 59 Domains with Python 59 Exploring the metadata for a domain and costs 61 Retrieving domain metadata 63 Retrieving domain metadata with Java 63 Retrieving domain metadata with PHP 64 Retrieving domain metadata with Python 64 [H]
Table of Contents Components of a domain's metadata 66 SimpleDB domain constraints 67 Items 67 Adding attributes to an item with Java 68 Adding attributes to an item with PHP 69 Adding attributes to an item with Python 69 Constraints on SimpleDB items 72 Attributes 72 Attributes with Java 73 Attributes with PHP 74 Attributes with Python 75 Constraints on SimpleDB item attributes 75 Values 76 Storing multiple values in a single attribute with Java 76 Storing multiple values in a single attribute with PHP 77 Storing multiple values in a single attribute with Python 78 Constraints on values of a SimpleDB item 79 Consistent Read and Conditional Put / Delete announcement 79 ConsistentRead = true for getattributes and Select 79 Conditional Put / Delete 82 Summary 84 Chapter 5: Data Types 85 What is lexicographical comparison? 86 Storing numeric values 87 Storing numeric values with Java 88 Storing numeric values with PHP 89 Storing numeric values with Python 90 Storing date values 91 Storing date values with Java 93 Storing date values with PHP 93 Storing date values with Python 94 Storing Boolean values 95 Storing Boolean values with Java 95 Storing Boolean values with PHP 95 Storing Boolean values with Python 96 XML-restricted characters 97 Using base64 values with Java 98 Using base64 values with PHP 99 Using base64 values with Python 100 Summary 100
Table of Contents Chapter 6: Querying 101 Sample data 102 Loading the sample data 103 Importing the sample data with Java 103 Importing the sample data with PHP 106 Importing the sample data with Python 109 Using Select 111 Simple select with Java 112 Simple select with PHP 113 Simple select with Python 115 Quoting values in Select expressions 116 Predicates in Select expressions 117 Simple predicate query with Java 117 Simple predicate query with PHP 118 Simple predicate query with Python 119 Comparison operators 119 Queries with Select 120 Comparison operators 121 Greater than 121 LIKE 122 NOT LIKE 123 BETWEEN 124 IN 125 IS NULL 126 IS NOT NULL 126 EVERY() 127 Combining expressions 128 INTERSECTION 129 NOT 130 OR 132 Sorting 133 Counting the results 135 COUNT() 135 Queries on multi-valued attributes 135 Querying for multi-valued attributes 136 getattribute 136 getattributes in Java 136 getattributes in PHP 137 getattributes in Python 139 Summary 139
Python Table of Contents Chapter 7: Storing Data on S3 141 Amazon S3 141 Buckets 142 Objects 142 Keys 143 Pricing for S3 143 Plan of action 145 Creating an S3 bucket 146 Creating an S3 bucket with Java 146 Creating an S3 bucket with PHP 147 Creating an S3 bucket with Python 147 Creating additional metadata 148 Creating additional metadata with Java 149 Creating additional metadata with PHP 151 Creating additional metadata with Python 151 Uploading the songs to S3 154 Uploading the songs to S3 with Java 154 Uploading the songs to S3 with PHP 155 Uploading the songs to S3 with Python 160 Retrieving the files from S3 161 Retrieving the files from S3 with Java 161 Retrieving the files from S3 with PHP 162 Retrieving the files from S3 with Python 163 Summary 165 Chapter 8: Tuning and Usage Costs 167 BoxUsage 167 Computing costs using BoxUsage 168 Usage reports 169 BoxUsage Java 172 Cost of Select 173 BoxUsage PHP 175 Cost of NextToken 175 Cost of Select 177 Cost of creating a domain 177 Cost of creating items 178 BoxUsage 178 Partitioning 180 Summary 181 Chapter 9: Caching 183 Caching 184 Memcached 184 Memcached and security 186 Installing memcached 186 [v]
Table of Contents Installing memcached client 189 Memcached client in Java 189 Memcached client in PHP 189 Memcached client in Python 189 Storing and retrieving data from memcached 190 Storing and retrieving data from memcached in Java 190 Storing and retrieving data from memcached in PHP 191 Storing and retrieving data from memcached in Python 192 Cache_Lite 193 Logic flow for using caching with SimpleDB 193 Using memcached with SimpleDB in Java 194 Using CacheJJte with SimpleDB in PHP 197 Using memcached with SimpleDB in Python 201 Summary 203 Chapter 10: Parallel Processing 205 BatchPutAttributes 205 BatchPutAttributes in Java 206 BatchPutAttributes in PHP 209 BatchPutAttributes in Python 211 Serialized SimpleDB requests 213 Parallelizing SimpleDB requests 214 Parallelizing SimpleDB requests in Java 214 Parallelizing SimpleDB requests in PHP 217 Parallelizing SimpleDB requests in Python 217 Simple threading 218 Threading with queues 220 Threading with workerpool 221 Concurrency and SimpleDB 223 Summary 224 Index 225