D o w n l o a d f r o m W o w ! e B o o k < w w w . w o w e b o o k . c o m > Summary of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix 1. Welcome to Cloud Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2. Amazon Web Services Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3. Tooling Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4. Storing Data with Amazon S3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 5. Web Hosting with Amazon EC2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 6. Building a Scalable Architecture with Amazon SQS . . . . . . . . . . . . . . . . . . 141 7. EC2 Monitoring, Auto Scaling, and Elastic Load Balancing . . . . . . . . . . . . 179 8. Amazon SimpleDB: A Cloud Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 9. Amazon Relational Database Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 D 10. Advanced AWS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 o 11. Putting It All Together: CloudList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 w Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 n l o a d f r o m W o w ! e B o o k < w w w . w o w e b o o k . c o m > D o w n l o a d f r o m W o w ! e B o o k < w w w . w o w e b o o k . c o m > HOST YOUR WEB SITE IN THE CLOUD D o w n AMAZON WEB SERVICES MADE EASY l o a BY JEFF BARR d f r o m W o w ! e B o o k < w w w . w o w e b o o k . c o m > iv Host Your Web Site in the Cloud: Amazon Web Services Made Easy by Jeff Barr Copyright ©2010 Amazon Web Services, LLC, a Delaware limited liability company, 1200 12th Ave S., Suite 1200, Seattle, WA 98144, USA Program Director: Lisa Lang Chief Technical Officer: Kevin Yank Technical Editor: Andrew Tetlaw Indexer: Fred Brown Technical Editor: Louis Simoneau Cover Design: Alex Walker Editor: Kelly Steele Expert Reviewer: Keith Hudgins Printing History: First Edition: September 2010 Notice of Rights All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted D in any form or by any means, without the prior written permission of the copyright holder, except in the case of brief quotations embedded in critical articles or reviews. o w Notice of Liability n The author and publisher have made every effort to ensure the accuracy of the information herein. l o However, the information contained in this book is sold without warranty, either express or implied. a Neither the authors and SitePoint Pty Ltd, nor its dealers or distributors will be held liable for any damages to be caused either directly or indirectly by the instructions contained in this book, or by the d software or hardware products described herein. f r o Trademark Notice m Rather than indicating every occurrence of a trademarked name as such, this book uses the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of W the trademark. o Helmet image on the cover is a Davida Jet and was kindly provided by http://motociclo.com.au. w ! e B Published by SitePoint Pty Ltd o Web: www.sitepoint.com o Email: [email protected] k ISBN 978-0-9805768-3-2 < Printed and bound in the United States of America w w w . w o w e b o o k . c o m > v About the Author Jeff Barr is currently the Senior Evangelist at Amazon Web Services. In this role, Jeff speaks to developers at conferences and user groups all over the world. Jeff joined Amazon.com in 2002 when he realized it was destined to become the next great developer platform, and that he could help make it so. Before coming to Amazon, Jeff ran his own consulting practice, and has also held management and development positions at Microsoft, eByz, KnowNow, and Visix Software. Jeff earned a Bachelor’s degree in Computer Science from the American University in Washington DC and also took some graduate classes at George Washington University in the same city. Jeff resides in Sammamish, Washington with his wife and their five children. In his spare time he enjoys the great outdoors, electronics, and welding. About the Technical Editors Andrew Tetlaw has been tinkering with web sites as a web developer since 1997. He’s ded- D icated to making the world a better place through the technical editing of SitePoint books, o kits, articles, and newsletters. Andrew’s also a busy father of five, enjoys receiving beer w showbags, and often neglects his blog at http://tetlaw.id.au/. n Louis Simoneau joined SitePoint in 2009, after traveling from his native Montréal to Calgary l o and finally Melbourne. He now gets to spend his days learning about cool web technologies, a an activity that had previously been relegated to nights and weekends. He enjoys hip-hop, d spicy food, and all things geeky. His personal web site is http://louissimoneau.com/ and his latest blog project is http://growbuycookeat.com/. f r o About the Chief Technical Officer m As Chief Technical Officer for SitePoint, Kevin Yank keeps abreast of all that is new and W exciting in web technology. Best known for his book, BuildYourOwnDatabaseDrivenWeb o SiteUsingPHP&MySQL, he also co-authored SimplyJavaScriptwith Cameron Adams and w EverythingYouKnowAboutCSSIsWrong!with Rachel Andrew. In addition, Kevin hosts the SitePointPodcastand co-writes the SitePointTechTimes, a free email newsletter that ! goes out to over 240,000 subscribers worldwide. e B Kevin lives in Melbourne, Australia and enjoys speaking at conferences, as well as visiting o friends and family in Canada. He’s also passionate about performing improvised comedy o theater with Impro Melbourne (http://www.impromelbourne.com.au/) and flying light aircraft. k Kevin’s personal blog is Yes,I’mCanadian(http://yesimcanadian.com/). < w w w . w o w e b o o k . c o m > vi About SitePoint SitePoint specializes in publishing fun, practical, and easy-to-understand content for web professionals. Visit http://www.sitepoint.com/ to access our blogs, books, newsletters, articles, podcasts, and community forums. D o w n l o a d f r o m W o w ! e B o o k < w w w . w o w e b o o k . c o m > ToCarmen, D Thanksforallofyourlove, o support,andencouragement.I w couldn'thavedoneitwithoutyou! n l o a d f r o m W o w ! e B o o k < w w w . w o w e b o o k . c o m > D o w n l o a d f r o m W o w ! e B o o k < w w w . w o w e b o o k . c o m > Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Who Should Read This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi What’s Covered in This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi The Book’s Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii The Code Archive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii Updates and Errata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii The SitePoint Forums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv The SitePoint Newsletters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv The SitePoint Podcast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv Your Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv D Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv o w Conventions Used in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv n Markup Samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv l o Tips, Notes, and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi a d Chapter 1 Welcome to Cloud Computing . . . . . . . . 1 f r o Avoiding a Success Disaster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 m Tell Me about Cloud Computing! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 W What’s a Cloud? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 The Programmable Data Center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 o w Characterizing the Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 ! Some Common Misconceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 e Cloud Usage Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 B Cloud Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 o Hosting Static Web Sites and Complex Web Applications . . . . . . . . 14 o k Software Development Life Cycle Support . . . . . . . . . . . . . . . . . . . . 14 < Training . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 w w w . w o w e b o o k . c o m >