ProgrammingAmazonWebServices
byJamesMurty
Publisher:O'Reilly
PubDate:March15,2008
PrintISBN-13:978-0-59-651581-2
Pages:600
TableofContents|Index
Overview
Buildingonthesuccessofitsstorefrontandfulfillmentservices,
Amazonnowallowsbusinessesto"rent"computingpower,data
storageandbandwidthonitsvastnetworkplatform.Thisbook
demonstrateshowdevelopersworkingwithsmall-tomid-sized
companiescantakeadvantageofAmazonWebServices(AWS)
suchastheSimpleStorageService(S3),ElasticComputeCloud
(EC2),SimpleQueueService(SQS),FlexiblePaymentsService
(FPS),andSimpleDBtobuildweb-scalebusinessapplications.
WithAWS,AmazonoffersanewparadigmforITinfrastructure:
usewhatyouneed,asyouneedit,andpayasyougo.
ProgrammingWebServicesexplainshowyoucanaccess
Amazon'sopenAPIstostoreandrunapplications,ratherthan
spendprecioustimeandresourcesbuildingyourown.Withthis
book,you'lllearnallthetechnicaldetailsyouneedto:
Storeandretrieveanyamountofdatausingapplication
servers,unlimiteddatastorage,andbandwidthwiththe
AmazonS3service
BuycomputingtimeusingAmazonEC2'sinterfaceto
requisitionmachines,loadthemwithanapplication
environment,manageaccesspermissions,andrunyour
imageusingasmanyorfewsystemsasneeded
UseAmazon'sweb-scalemessaginginfrastructuretostore
messagesastheytravelbetweencomputerswithAmazon
SQS
LeveragetheAmazonFPSservicetostructurepayment
instructionsandallowthemovementofmoneybetweenany
twoentities,humansorcomputers
Createandstoremultipledatasets,queryyourdataeasily,
andreturntheresultsusingAmazonSimpleDB.
Scaleupordownatamoment'snotice,usingthese
servicestoemployasmuchtimeandspaceasyouneed
Whetheryou'restartinganewonlinebusiness,needtorampup
existingservices,orrequireanoffsitebackupforyourhome,
ProgrammingWebServicesgivesyouthebackgroundandthe
practicalknowledgeyouneedtostartusingAWS.Otherbooks
explainhowtobuildwebservices.Thisbookteachesbusinesses
howtotakemakeuseofexistingservicesfromanestablished
technologyleader.
ProgrammingAmazonWebServices
byJamesMurty
Publisher:O'Reilly
PubDate:March15,2008
PrintISBN-13:978-0-59-651581-2
Pages:600
TableofContents|Index
Copyright
Dedication
Preface
Chapter1.InfrastructureintheCloud
Section1.1.AmazonWebServicesforInfrastructure
Section1.2.ThinkingLikeAmazon
Section1.3.RealityCheck
Section1.4.Interfaces:RESTandQueryVersusSOAP
Chapter2.InteractingwithAmazonWebServices
Section2.1.REST-BasedAPIs
Section2.2.UserAuthentication
Section2.3.PerformingAWSRequests
Chapter3.S3:SimpleStorageService
Section3.1.S3Overview
Section3.2.InteractingwithS3
Section3.3.Buckets
Section3.4.Objects
Section3.5.AlternativeHostnames
Section3.6.AccessControlLists
Section3.7.ServerAccessLogging(Beta)
Section3.8.SignedURIs
Section3.9.DistributingObjectswithBitTorrent
Chapter4.S3Applications
Section4.1.ShareLargeFiles
Section4.2.OnlineBackupwithAWS::S3
Section4.3.S3FilesystemwithElasticDrive
Section4.4.MediatedAccesstoS3withJetS3t
Chapter5.EC2:ElasticComputeCloud(Beta)
Section5.1.EC2Overview
Section5.2.InteractingwithEC2
Section5.3.Keypairs
Section5.4.NetworkSecuritybyIP
Section5.5.FindingAmazonMachineImages
Section5.6.ControllingInstances
Section5.7.LogIntoanInstance
Section5.8.SecurityGroups
Section5.9.ManagingandSharingAMIs
Section5.10.ConsoleOutputandInstanceReboot
Chapter6.UsingEC2InstancesandImages
Section6.1.EC2InstancesinDetail
Section6.2.DataManagementinEC2
Section6.3.ModifyinganAMI
Section6.4.RegisteringanAMI
Section6.5.CreateanAMIfromScratch
Chapter7.EC2Applications
Section7.1.DynamicDNS
Section7.2.On-DemandVPNServerwithOpenVPN
Section7.3.WebPhotoAlbumwithGallery2
Chapter8.SQS:SimpleQueueService
Section8.1.SQSOverview
Section8.2.InteractingwithSQS
Section8.3.Queues
Section8.4.Messages
Section8.5.QueueAttributes
Section8.6.QueueAccessControl
Chapter9.SQSApplications
Section9.1.MessagingSimulator
Section9.2.DistributedApplicationServiceswithBOTO
Section9.3.AutomatedManagementofEC2InstancePools
withLifeguard
Chapter10.FPS:FlexiblePaymentsService(Beta)
Section10.1.FPSOverview
Section10.2.InteractingwithFPS
Section10.3.ManagingYourTokens
Section10.4.AcquiringThird-PartyTokens
Section10.5.PayNowWidgets
Chapter11.FPSTransactionsandAccounts
Section11.1.PerformingFPSTransactions
Section11.2.AccountManagementandInformation
Chapter12.FPSAdvancedTopics
Section12.1.GatekeeperLanguageGuide
Section12.2.MicropaymentswithFPS
Section12.3.BuildingaMarketplaceApplication
Section12.4.SubscribingtoFPSEventNotifications
Chapter13.SimpleDB(Beta)
Section13.1.SimpleDBOverview
Section13.2.InteractingwithSimpleDB
Section13.3.Domains
Section13.4.ItemsandAttributes
Section13.5.RepresentingDatainSimpleDB
Section13.6.PerformingQueries
Section13.7.StockPriceDatabase:AMiniSimpleDB
Application
AppendixA.AWSResources
SectionA.1.AWSOnlineResources
SectionA.2.ClientTools
SectionA.3.APILibraries
SectionA.4.Third-PartyAWSSolutions
AppendixB.AWSAPIErrorCodes
SectionB.1.S3:SimpleStorageService
SectionB.2.EC2:ElasticComputeCloud
SectionB.3.SQS:SimpleQueueService
SectionB.4.FPS:FlexiblePaymentsService
SectionB.5.SimpleDB
Colophon
Index
Copyright
Copyright©2008,JamesMurty.Allrightsreserved.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reillybooksmaybepurchasedforeducational,business,or
salespromotionaluse.Onlineeditionsarealsoavailablefor
mosttitles().Formoreinformation,
contactourcorporate/institutionalsalesdepartment:(800)
998-9938or
Editor:MikeLoukides
ProductionEditor:SumitaMukherji
NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
TheimageofanAtlanticwreckfishandrelatedtradedressare
trademarksofO'ReillyMedia,Inc.
Manyofthedesignationsusesbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.
ForBec
Preface
AmazonWebServices(AWS)isthenameofasuiteofweb
servicesmadeavailablebyAmazonthatallowthird-party
developerstoaccessandbuildonthecompany'stechnology
platform.Thissuiteincludesanumberofinfrastructureservices
thatcanaugmentorreplacethetraditionalphysical
infrastructurerequiredbywebapplications.Theseinfrastructure
servicesprovidestorage,computingpower,amessaging
system,apaymentsystem,andadatabasethatcanbe
accessedbyanyonewithanAmazon.comaccountandacredit
card.Bestofall,withtheseservicesyoupayonlyforwhatyou
use.Whetheryouaremerelyexperimentingwiththeservicesor
usingthemasaplatformforwebapplicationsserving
thousandsofusers,yourentonlytheinfrastructureyouneed
andonlywhenyouneedit.
Theseservicesofferacompellingalternativetobuildingyour
applicationsontopofstandard,physicalhardware,because
theycanprovidethescalable,reliable,andcost-effective
infrastructurecomponentsyouneedwithouttheexpenseor
effortinvolvedinmanagingyourownhardware.Theygiveyou
thefreedomtoconcentrateonyourapplicationinsteadofthe
physicalplatformitrunson.Theyalsosignificantlyreducethe
initialinvestmentrequiredtobuildandofferaservice,while
givingyouconfidencethatyourapplicationwillbeabletonot
onlysurviveanysuddenattentionitreceives,buttogrowand
thriveinresponse.Byleavingtheinfrastructuremanagementto
Amazon,youcanfocusondevelopingyourapplicationand
growingyourbusiness.
Withtheexpenseofinfrastructureremovedfromtheequation,
anyonebuildingwebapplicationscancompeteandsucceed
basedontheirinnovation,execution,andideasinsteadofbeing
limitedbytheirresources.JeffBezos,theCEOofAmazon,has
famouslyreferredtoITinfrastructureanditsattendantsetup,
management,andexpenseheadachesas"muck."Indeclaring
"Wemakemucksoyoudon'thaveto,"Bezoshasofferedto
handlethemucky,infrastructuresideofwebapplicationsand
allowtherestofustofocusontheinterestingside.Perhapsyou
shouldtakehimupontheoffer.
P.1.What'sinThisBook?
Inthisbookweexplorethesetofwebservicesofferedby
Amazonthatprovidepay-as-you-go,virtualinfrastructure,and
welookatthepracticalitiesofdesigningandbuilding
applicationstotakeadvantageofAmazon'sinfrastructure
services.Wewillprovidedetailedsamplecodethatshowshow
tointeractwiththeservices'applicationprograminterfaces
(APIs),andwewilldiscusshowtheservicescanbeused
individuallyandincombinationtobuildsystemsinthereal
world.
Thefirsttwochaptersintroducetheserviceswewilluseinthis
bookanddiscusshowtheyworkattheHTTPmessaginglevel:
Chapter1
Inthischapter,weintroduceAmazon'sinfrastructure
servicesanddiscussthemainadvantagesand
disadvantagesofusingonlineservicestomeetyour
infrastructureneeds.TouseAmazon'sserviceseffectively,
youmayhavetoadjustyourmindsetandexpectations:
thingsworkdifferentlyinthecloud.
Chapter2
TointeractwiththeAmazonWebServices,youwillneeda
communicationslibrarytocreaterequestmessagesthatare
structuredtobereadabletotheservices,andauthenticated
sothatonlyyoucanaccessyourprotecteddata.Youwill
alsoneedtounderstandtheresponsemessagesthe
servicesreturn.Inthischapter,wedescribehowto
constructandinterprettheHTTPmessagesusedby
Amazon'sAPIinterfaces.Wewillalsoprovidecodethat
demonstratesexactlyhowtoworkwiththesemessages.
Theremaining11chaptersinthebookfocusonactuallyusing
theservicesthroughtheirAPIinterfacesorbybuildingonthirdpartylibrariesorservices.
Wedevotesevenchapterstoexplainingthekeyconcepts,data
models,behavior,andAPIsofAmazon'sfiveinfrastructure
services:S3,EC2,SQS,FPS,andSimpleDB.Thesechapters
describethefeaturesandcapabilitiesofeachserviceand
provideanoverviewoftheoperationsexposedbytheservice.
TheyalsoincludeclientimplementationcodewritteninRuby
andstep-by-stepguidestoperformingtaskswiththeAPI
operations.Youcanuseoursamplecodetofollowalongwith
theinteractivesessionsinthesechaptersandasastarting
pointforyourownapplications.
ForS3,EC2,andSQS,wehaveincludedadditionalchaptersin
whichweguideyouthroughtheprocessofbuildingfully
functionalapplicationsbasedontheservices.Theseapplications
serveasrealisticexamplesofhowtoputtheinfrastructure
servicestowork.Inthesechapters,wewilldemonstratehowto
usethemtoperformcommontasks,andwewillshowoffsome
ofthemanythird-partylibrariesandtoolsthatareavailablefor
theseservices:
Chapter3
HowtouseAmazon'sSimpleStorageService(S3)for
onlinedatastorage.
Chapter4
Useyouronlinedatastoragespacetosharelargefileswith
othersandbackupyourfiles.Youcanalsoaccessyour
storageasifitwereastandardLinuxblockdevice,oryou
cancreateamediatedaccesssystemtograntotherslimited
andwell-controlledaccesstoyourownS3storage.
Chapter5
HowtouseAmazon'sElasticComputeCloud(EC2)service
foronlinecomputingresources.
Chapter6
LearnhowvirtualLinuxserverinstancesoperateintheEC2
serviceandhowtocreateyourowninstances,customized
toworkexactlythewayyouwant.
Chapter7
Usevirtualserverstocreateanon-demand,secureVPNfor
protectingyournetworktraffic,ortohostawebsite
applicationthatwillbemadeavailabletothepublic.
Chapter8
HowtouseAmazon'sserviceforonlinemessaging.
Chapter9
Usemessagingtotietogetherthecomponentsofa
distributedapplication.Inthischapterwecombinethe
capabilitiesoftheS3,EC2,andSQSservicestobuilda
service-orientedapplicationthatcanconvertvideoand
imagefilesorperformotherdata-processingtasks.Wealso
demonstratehowtoautomatethemanagementofthis
applicationsoitcanrespondtodemandwithoutmanual
intervention.
Chapter10,Chapter11,andChapter12
HowtouseAmazon'sFlexiblePaymentsService(FPS)for
financialtransactions.FPSisbigandcomplicatedenoughto
needthreechapters.
Chapter13
HowtouseAmazon'sSimpleDBserviceasanonline
database.Thischapterincludestwosimpleexamplesthat
demonstratehowtoloadstockpricedataintoyour
database,andhowtoimplementalocaldatacachetohelp
speedupyourSimpleDBapplications.
P.2.RubyandInteractiveExamples
Wehavewrittenthevastmajorityofourexamplecodeinthe
Rubylanguage.Rubyhastwopowerfulfeaturesthatmakeit
ideallysuitedtoourpurposesinthisbook.First,Rubycodeis
lovely:itisconcise,succinct,andrelativelyeasytofollow,even
fordeveloperswhoarenotfamiliarwiththelanguage.Ruby
codecanbealmostasbriefaspseudo-code,andyetitis
entirelyfunctional.Second,Rubyisaninterpretedlanguage
thatallowsyoutowrite,rewrite,andruncodeinaninteractive
session.ThecodeinthisbookwaswrittentoworkwithRuby
versions1.8.6andlater.
WewilltakeadvantageofRuby'ssupportforinteractive
sessionsaswebuildtheserviceAPIimplementationsthatwill
allowustocommunicatewithAWSservices.Wewilladd
functionalitypiecebypiece,communicatingwiththeliveservice
ateachsteptotestthenewlyimplementedAPIoperations.This
approachallowsustoshowexactlyhowtheservicesbehave,
anditprovidestheopportunitytofollowalongandlearnhow
theAPIsworkthroughhands-onexperimentation.
NOTE
IfyouaremorefamiliarwiththeJavaorPython
languagesthanwithRubyyouareinluck,aswehave
writtenAPIclientimplementationsintheselanguages
aswell.Visittheonlineresourceswebpageforthis
bookat
to
downloadclientprogramsinallthreelanguages.
WewillspendalotoftimeintheRubyshellprogramcalledirb,
aninteractiveinterpreterfortheRubylanguage.Thecommands
thatweruninirbwillbedenotedbythecommandprompt
irb>.
Ifyoudownloadedthesamplecodeforthisbookfromthe
O'Reillywebsite,youwillbeabletoloadthecodemodulesby
puttingtheminadirectoryinRuby'sloadpath,orthecurrent
directory,andissuingtherequirecommandinyourirb
session:
#LoadtheRubycodefilecalled'AWS.rb'
irb>require'AWS'
IfyouaretypingRubycodeintofilesasyoureadthroughthis
book,youwillloadacodefileinthesamewayinitially,butyou
needtouseadifferentcommandtoreloadafilewhose
contentshavechanged:
#ReloadthechangedRubycodefile'AWS.rb'.
irb>load'AWS.rb'
Noticethatyouarerequiredtotypethefullfilenamewhenyou
arereloadingachangedfilewiththeloadcommand,whereas
youcanomitthesuffix.rbwhenyouusetherequire
command.
P.3.ConventionsUsedinThisBook
Thefollowingtypographicalconventionsareusedinthisbook:
Italic
Indicatesnewterms,URLs,emailaddresses,filenames,file
extensions,pathnames,anddirectories
Constantwidth
Indicatescommands,options,variables,attributes,keys,
functions,classes,methods,modules,properties,
parameters,values,objects,thecontentsoffiles,XML
documents,HTMLdocuments,andtheoutputfrom
commands
Constantwidthbold
Showscommandsandothertextthatshouldbetyped
literallybytheuser
Constantwidthitalic
Indicatestheauthor'semphasiswithintheoutputfrom
commands,andcommandsenteredinaLinuxconsole
Thisiconsignifiesatip,suggestion,orgeneral
note.
Thisiconindicatesawarningorcaution.
P.4.UsingCodeExamples
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdonotneedtocontactusforpermission
unlessyouarereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesnotrequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesnotrequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdonotrequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"ProgrammingAmazonWebServices:S3,EC2,SQS,
FPS,andSimpleDBbyJamesMurty.Copyright2008James
Murty,978-0-596-51581-2."
Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseor
thepermissiongivenhere,feelfreetocontactusat
P.5.Safari®Enabled
NOTE
WhenyouseeaSafari®Enabledicononthecoverof
yourfavoritetechnologybook,thatmeansthebookis
availableonlinethroughtheO'ReillyNetworkSafari
Bookshelf.
Safarioffersasolutionthat'sbetterthane-books.It'savirtual
librarythatletsyoueasilysearchthousandsoftoptechbooks,
cutandpastecodesamples,downloadchapters,andfindquick
answerswhenyouneedthemostaccurate,currentinformation.
Tryitforfreeat.
P.6.HowtoContactUs
Pleaseaddresscommentsandquestionsconcerningthisbookto
thepublisher:
O'ReillyMedia,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
800-998-9938(intheUnitedStatesorCanada)
707-829-0515(internationalorlocal)
707829-0104(fax)
Wehaveawebpageforthisbook,wherewelisterrata,
examples,andanyadditionalinformation.Youcanaccessthis
pageat:
/>Tocommentorasktechnicalquestionsaboutthisbook,send
emailto:
Formoreinformationaboutourbooks,conferences,Resource
Centers,andtheO'ReillyNetwork,seeourwebsiteat:
P.7.Acknowledgments
Thisbookwouldnothavebeenpossiblewithoutthehelpand
excellentadvicegivenbymyeditorMichaelLoukides.
Manyotherscontributedtothisbookdirectlyorindirectly.
SpecialthanksgotoLucasCarlson,LeonardRichardson,
ChristopherMylonas,andJackTruongfortheirhelpfulfeedback.
ThecommunityofdevelopersandAmazonstaffintheAWS
Developerforumshasbeenaninvaluableresourcefor
researchingthetechnicaldetailsoftheAmazonWebServices
andunderstandinghowbesttousethemintherealworld.
Totheextentthatthisbookprovidesanaccurateanduseful
referencefordevelopersorusersofAmazonWebServices,I
oweadebtofgratitudetoeveryonementionedabove.Any
faults,errors,oromissionsinthisbookaremyown.
Chapter1.InfrastructureintheCloud
TheWorldWideWebhasgrownquicklyoverthelastcoupleof
decadestobecomeaninvaluableresourceforcommunication,
research,andentertainment.TheWebhasalsobecomean
openplatformonwhichpowerfulservicesandapplicationscan
bebuiltbyestablishedcompaniesandnewcomersalike.Itisa
veryaccessibleplatformthatallowsevensmallcompaniesto
createwebapplicationsandbuildabusinesswithoutrequiring
thebackingofalargeenterprise.Apersonorgroupwithsome
expertise,sometime,andagoodenoughideacancreateaweb
applicationthatcompeteswiththeofferingsoflarger
corporations—orevencarvesoutanentirelynewmarket.On
theWeb,thesizeandmarketingcloutofalargecorporation
doesnotguaranteeitamonopolyontheattentionand
patronageofaglobalaudience.
TheWebisfullofopportunitiesforcompaniesbothlargeand
small,butthesmallercompaniesfaceadifficultproblem:
infrastructure.
Webapplicationsthatarepopularandhavethousandsofusers
requiresignificantinfrastructuretoprovidethehigh
performanceandsmoothexperiencethatusersdemand.
Industrial-strengthinfrastructureisveryexpensivetobuyand
maintain,sosmallercompanieswithfewerusersareoften
forcedtodowithout.Yetintoday'sworldofwebpublicityflash
stormscausedbysitessuchasSlashdotandDigg,the
differencebetweenawebapplicationservingafewdozenusers
andservingthousandsmaybenomorethanaglowingarticle
andafewhours'time.
Althoughthiskindofattentionmaybeexactlywhatyouhope
for,unlessyouhaveinvestedheavilyininfrastructure,your
applicationmaynotsurvivetheonslaught.Ontheotherhand,if
youspendtoomuchmoneyonservers,bandwidth,hosting,and
themanagementofallthisinfrastructure,therewillbelittleleft
todeveloptheapplicationitself.Adilemmafacingmanysmall
developmentteamsishowtostriketherightbalancebetween
investinginapplicationdevelopmentandfundingrobustand
scalableinfrastructure.
Amazonoffersanewandcompellingsolutiontothisdilemmain
theformofinfrastructurewebservices.Theseservicesallow
applicationdeveloperstoavoidaltogethertheburdenofbuying
andmaintainingphysicalinfrastructurebymakingitpossibleto
rentvirtualinfrastructureinstead.Inthisbookwewillshowyou
howyoucanbuildyourapplicationsontopofAmazon'sservices
andeffectivelyoutsourceyourinfrastructure.
1.1.AmazonWebServicesfor
Infrastructure
Inthisbook,wewillexaminefourofferingsfromAmazonWeb
Services(AWS)thatprovideflexibleandaffordable
infrastructurecomponentsonwhichyoucanbuildindustrialstrengthwebapplications.
AmazonSimpleStorageService:S3
AmazonSimpleStorageService(S3)offerssecureonline
storagespaceforanykindofdata,providinganalternative
tobuilding,maintaining,andbacking-upyourownstorage
systems.Itmakesyourdataaccessibletoanyother
applicationsorindividualsyouallowfromanywhereonthe
Web.Therearenolimitsonhowmuchdatayoucanstorein
theservice,howlongyoucanstoreit,oronhowmuch
bandwidthyoucanusetotransferorpublishit.
S3isascalable,distributedsystemthatstoresyour
informationreliablyacrossmultipleAmazondatacenters,
anditisabletoserveitquicklytomassiveaudiences.Its
storageapplicationprogramminginterface(API)is
deliberatelysimpleandmakesnoassumptionsaboutthe
natureofthedatayouarestoring.Thissimplicitymeans
youcanmaintaincompletecontroloverhowyourdatais
representedintheservice.
AmazonElasticComputeCloud:EC2(beta)
AmazonElasticComputeCloud(EC2)makesitpossibleto
runmultiplevirtualLinuxserversondemand,providingas
manycomputersasyouneedtoprocessyourdataorrun
yourwebapplicationwithouthavingtopurchaseorrent
physicalmachines.InEC2youhavefullcontrolovereach
serverwithrootaccesstotheoperatingsystem(theroot
useristheultimatesystemadministratoronLinux
machines),aconfigurablefirewalltomanagenetwork
access,andthefreedomtoinstallanysoftwareyouplease.
OnceyouhavesetupanEC2serverthewayyoulikeit,you
cansaveitpermanentlyasaserverimage.Youcanthen
launchnewserversfromthisimagetocreatevirtual
machinesthatarepreconfiguredandreadytodoyour
bidding.
TheEC2serviceofferscomputingresourcesthatarevery
flexible.Youcanrunasmanyserversasyouneedforas
longasyouneedthem,andyoucanshutthemalldown
whentheyhaveservedtheirpurpose.Theserviceoffersan
APItostartandstopserverinstances,applyaccessand
networkingpermissions,andmanageyourserverimages.
YoumanageeachindividualserverusingstandardLinux
toolsoverasecureshellsession.
NOTE
Atthetimeofthiswriting,theEC2serviceisstillin
beta.Thismeansthattheservice'sfeaturesarestill
evolvingquickly,andthereisanincreasedriskof
problemsthatmaymaketheserviceunsuitablefor
useinproductionsystems.
AmazonSimpleQueueService:SQS
AmazonSimpleQueueService(SQS)deliversshort
messagesbetweenanycomputersorsystemswithaccess
totheInternet,allowingthecomponentsofyourdistributed
webapplicationstocommunicatereliablywithoutyou
havingtobuildormaintainyourownmessagingsystem.
WithSQSyoucansendanunlimitednumberofmessages
viaanunlimitednumberofmessagequeues,andyoucan
configuretheperformancecharacteristicsandaccess
permissionsforeachqueue.Theserviceusesamessage
lockingandtimeoutmechanismthathelpsprevent
messagesfrombeingdeliveredmorethanonce,whilestill
ensuringtheywillbedelivereddespiteanycomponent
failuresornetworkdropouts.
SQSisimplementedasadistributedapplicationwithin
Amazon.Yourmessagesarestoredredundantlyacross
multipleserversanddatacenters.Theservice'sAPIallows
youtosendandreceivemessages,andtocontroltheirfull
lifecycle.
FlexiblePaymentsService:FPS(Beta)
AmazonFlexiblePaymentsService(FPS)transfersmoney
betweenindividualsorcompaniesthathaveAmazon
Paymentsaccounts,allowingyoutobuildapplicationsthat
provideanonlinestoreorthatimplementamarketplace
betweencustomersandthird-partyvendors.WithFPSyou
canmakepaymentsfromtraditionalsources,suchascredit
cardsandbankaccounts,orfromsourcesinternalto
AmazonPaymentsaccountsthathavelowerfeesandare
designedtomakemicro-paymenttransactionsfeasible.
Alltransactionsneedtobeauthorizedbyeveryoneinvolved
inthetransaction.Thepartiesinvolvedcanimposedetailed
constraintsontransactions,suchashowandwhen
transactionscanbeperformed,howmuchmoneycanbe
transferred,andwhocansendandreceivethefunds.
CustomersinteractwithyourFPSapplicationthroughan
AmazonPaymentsgatewayusingtheirAmazon.com
account.BecausethetransactionsaremediatedbyAmazon,
yourcustomersarenotrequiredtoprovideyouwiththeir
personalbankinginformation,andyoudonothavethe
burdenofsecurelystoringthishighlysensitiveinformation.
NOTE
Atthetimeofthiswriting,theFPSserviceisstillin
beta.Thismeansthattheservice'sfeaturesarestill
evolvingquickly,andthereisanincreasedriskof
problemsthatmaymaketheserviceunsuitablefor
useinproductionsystems.Thefullfunctionalityof
theserviceisonlyavailabletodevelopersorusers
withU.S.-basedcreditcardsandbankaccounts.
Internationaluserscanaccessonlylimited
functionality.
AmazonSimpleDB(Beta)
AmazonSimpleDB(SimpleDB)storessmallpiecesoftextual
informationinasimpledatabasestructurethatiseasyto
manage,modifyandsearch.Ifyourapplicationreliesona
relativelysimpledatabase,thisservicecanreplaceyour
traditionalrelationaldatabase(RDBMS)serverleavingyou
withonelesspieceofinfrastructuretopurchaseand
maintain.
SimpleDBisdesignedtominimizethecomplexityand
administrativeoverheadinvolvedinmanagingyourdata.It
doesnotrequireapre-definedschemasoyoucanalterthe
structureandcontentofyourdatabasewheneveryouneed
to.Itindexeseverypieceofinformationyoustoresoall
yourqueriesrunquickly.Anditstoresyourdatasecurely,
redundantlyandsafelywithinAmazon'snetworkofdata
centers.
NOTE
Atthetimeofthiswriting,theSimpleDBserviceisstill
inbeta.Thismeansthattheservice'sfeaturesarestill
evolvingquickly,andthereisanincreasedriskof
problemsthatmaymaketheserviceunsuitableforuse
inproductionsystems.
Thesefivewebservices—S3,EC2,SQS,FPS,andSimpleDB—
sharethesamefundamentalcharacteristics.Theyarepay-asyou-go,meaningyoupaypredictablefeesbasedonhowmuch
orhowlittleyouusetheservice.Therearenoinitialcoststo
join,nolong-termsubscriptionpayments,andtheusagefees
areattractivelylow.Theservicesarehighlyscalable,
performingequallywellinmodestormassivelydemanding
usagescenarios.Thismeansthattheapplicationsbuiltonthem
canbesimilarlyscalableandareabletogrowrapidlyatshort
noticewithouthittinglimitsimposedbyinsufficient
infrastructure.Onesignificantfeatureisthatalltheservicesare
designedtobehighlyreliableandfault-tolerant:theservices
anddataresourcesaredistributedacrossmultipleserversand
datacenterswithinAmazon'sinfrastructure,andtheyare
managedbyacompanywithsignificantexperienceand
investmentsintheoperationofaglobalwebbusiness.
1.1.1.SigningUpforAmazonWebServices
TouseAWSyoufirstneedtoregisterforanaccountand
provideacreditcardtobebilledforyourserviceusage.Ifyou
alreadyhaveanAmazon.comaccountforAmazon'sonline
store,youcanassociateyourAWSmembershipwiththis
existingaccount.
CreateanewAWSaccountattheAWShomepage
—.Thisiswhereyoucanmanage
yourAWSaccount,signupforservices,viewyourservice
activity,andtrackbillinginformation.
Figure1-1.ScreenshotofimportantelementsintheAWS
homepage
OnceyouhaveregisteredforanAWSaccount,youneedtosign
upseparatelyforeachAWSserviceyouwishtouse.Ifyouhave
notexplicitlysignedupforaservice,youwillnotbeableto
accessitsAPI.Tosignupforaservice,visitthehomepagefor
thatserviceandclickonthebutton"SignUpForThisWeb
Service."
Herearethehomepagesfortheinfrastructureserviceswe
discussinthisbook:
SimpleStorageService(S3)
/>ElasticComputeCloud(EC2)
/>