Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Boost application development with Amazon web Services, Part 1: How to use the Amazon E-Commerce Service

Eric Giguerre (ericgiguere@ericgiguere.com), Software Developer, Studio B
Eric Giguere is a software developer and author who has written numerous articles and several books about all kinds of programming topics. Having just finished his fourth book, "Make Easy Money with Google," he's hard at work on a follow-up title.

Summary:  This tutorial provides an overview of Amazon Web Services (AWS). AWS exposes raw product information and key parts of Amazon.com technology to third-party developers for use in their applications. After describing how AWS works in general, the tutorial focuses on the main AWS service, called the Amazon E-Commerce Service (ECS). As part of this tutorial, you will develop a small web application that uses ECS to display book and music information.

View more content in this series

Date:  24 Jun 2005
Level:  Intermediate PDF:  A4 and Letter (407 KB | 35 pages)Get Adobe® Reader®

Activity:  17367 views
Comments:  

Dive into ECS

Understanding ECS

ECS is the Amazon service that most programmers use. It has great appeal for developers for several reasons:

  • It provides access to the vast amount of information contained in Amazon's product databases.
  • It can be used as an opportunity to make money through the Amazon Affiliates program.
  • Access to ECS is free of charge.

Note that ECS is a read-only service: You can't submit information to Amazon using ECS. Instead, you must use alternate channels and APIs to add or modify product listings, customer reviews, and so on. The only exception is that you can create and fill shopping carts for users and submit those carts to Amazon for presentment and approval by the user.

ECS can be used by stand-alone Java applications or by web applications. The ECS Developer Guide lists a variety of possible uses for ECS:

  • Presenting detailed information about Amazon products on your own site, including up-to-date prices
  • Monitoring statistics for how well products are doing or how competitors are pricing their products
  • Building a niche online store using Amazon's own technology
  • Developing software products and services for other ECS users

Most of these uses are commercial in nature, but it doesn't have to be that way. If you're building software to organize book or music collections, for example, you can quickly download cover art for a given book or album using a few simple ECS calls. (Note: Be sure to read the AWS licensing terms closely for restrictions on using cover art and other copyrighted materials that Amazon provides.)

ECS is also a great way to experiment with web services in general, because the services that AWS provides are easily understood (everyone can relate to browsing and purchasing books and menus) and are free to use.


Access ECS: REST versus SOAP

You can access all services available through ECS in one of two ways:

  • As Representational State Transfer (REST) requests
  • As SOAP requests

The first way -- through REST -- is the most simple to understand. REST uses HTTP as its underlying transport. You pass REST commands and options to ECS by using URL query parameters; ECS returns an XML document containing the result. This process makes it possible to invoke ECS services directly from a Web browser, as in this example:

http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=
					xxxx&Operation=ItemLookup&ItemId=0321321146

The result is an XML document describing the book with ISBN 0321321146:

<?xml version="1.0" encoding="UTF-8"?>
<ItemLookupResponse 
        xmlns="http://webservices.amazon.com/AWSECommerceService/2005-03-23">
  <OperationRequest>
    <HTTPHeaders>
      <Header Name="UserAgent" Value="Mozilla/5.0 Gecko/20041001 Firefox/0.10.1"/>
    </HTTPHeaders>
    <RequestId>0PJ4DG95DYN2JGQ7ZSYE</RequestId>
    <Arguments>
      <Argument Name="Service" Value="AWSECommerceService"/>
      <Argument Name="Style" Value="http://www.ericgiguere.com/tohtml.xsl"/>
      <Argument Name="SubscriptionId" Value="xxxx"/>
      <Argument Name="ItemId" Value="0321321146"/>
      <Argument Name="Operation" Value="ItemLookup"/>
    </Arguments>
    <RequestProcessingTime>0.0185689926147461</RequestProcessingTime>
  </OperationRequest>
  <Items>
    <Request>
      <IsValid>True</IsValid>
      <ItemLookupRequest>
        <ItemId>0321321146</ItemId>
      </ItemLookupRequest>
    </Request>
    <Item>
      <ASIN>0321321146</ASIN>              
      <DetailPageURL>http://www.amazon.com/exec/obidos/redirect?tag=ws%26link_code=xm2
      %26camp=2025%26creative=165953%26path=
      http://www.amazon.com/gp/redirect.html%253fASIN=0321321146
      %2526location=
      /o/ASIN/0321321146%25253FSubscriptionId=1WCK32SN05PGBJ0YV302</DetailPageURL>
      <ItemAttributes>
        <Author>Eric Giguere</Author>
        <ProductGroup>Book</ProductGroup>
        <Title>Make Easy Money with Google : Using the AdSense Advertising Program</Title>
      </ItemAttributes>
    </Item>
  </Items>
</ItemLookupResponse>						
						

You can even ask ECS to apply an Extensible Stylesheet Language Transformation (XSLT) stylesheet to the XML it returns, which is useful for transforming the Amazon data into a different format.

The more conventional approach to web services is to use SOAP. For each of its web sites, Amazon supplies Web Services Description Language (WSDL) documents that you use to import the ECS services into whatever web services toolkit you're using.

Which approach you take -- REST or SOAP -- is entirely up to you. Amazon supports both systems equally well.


Operations

Two general types of operation are available to ECS: lookups and searches.

You use a lookup to find detailed information about things like products, merchants, and even customers. When looking up products, you can request information for up to 10 products. The previous example looked up information for a single book by its ISBN using the ItemLookup request. (Products are identified in a number of ways, chiefly by the Amazon Standard Identification Number (ASIN). For books, ASIN and ISBN values are equivalent.) The following lookup operations are available in ECS 4.0:

  • BrowseNodeLookup
  • CustomerContentLookup
  • ItemLookup
  • ListLookup
  • SellerLookup
  • SellerListingLookup
  • SimilarityLookup
  • TransactionLookup

As you might guess, ItemLookup is the most common lookup operation.

A search operation searches the Amazon databases for information using criteria you supply. For example, you can get a list of all the books in the Amazon database written by a specific author. The following search operations are available in ECS 4.0:

  • CustomerContentSearch
  • ItemSearch
  • ListSearch
  • SellerListingSearch

The shopping cart operations are:

  • CartAdd
  • CartClear
  • CartCreate
  • CartGet
  • CartModify

Finally, you can use a Help operation to obtain help for other operations.

Options control how much information an operation returns and how that information is returned. As already mentioned, you can apply an XSLT stylesheet to the XML (for REST requests only) simply by passing the URL of the stylesheet (which must be available on a public Internet site) to Amazon as part of the request. You can use response groups to control the level of detail returned. Response groups tell AWS which subset of the possible data to return -- for example, do you just want basic information about a book (title, author, ranking, price) or do you want detailed information (customer reviews, availability from third-party stores, images).


Content caching

To ensure that its systems are available for everyone's use, Amazon limits how quickly you can make successive requests to AWS. Each IP address is limited to one request per second. If your application is going to make several requests in a short span of time, you'll have to spread them out over several seconds, which can lead to unacceptable performance, especially if the Amazon servers are very busy. Thus, caching becomes an important part of any AWS-based application.

When making REST requests, for example, you can use a simple cache built around the java.util.HashMap class, where the URL of the request acts as the key. Every time you make a successful AWS request, place the response data (ideally already transformed into whatever format makes sense for your application so that you don't have to keep re-parsing the XML) in the cache.

Note that Amazon restricts the amount of time you can cache information. According to the AWS licensing agreement, most data can be cached for no more than 24 hours, though some of the static product information -- things like author names, product names, and release dates -- can be cached for up to three months. Pricing and availability information can be cached for up to a week, but if you don't refresh the information on an hourly basis, you must include a timestamp with the information whenever it's displayed. Refer to Section D of the AWS licensing agreement for all the specifics.

4 of 11 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and Web services
ArticleID=137178
TutorialTitle=Boost application development with Amazon web Services, Part 1: How to use the Amazon E-Commerce Service
publish-date=06242005
author1-email=ericgiguere@ericgiguere.com
author1-email-cc=webserv@us.ibm.com