I couldn’t find any tutorials on how to use Amazon AWS with GroovyWS, so I took a few minutes to figure out how to do it. Here is some sample code:

import groovyx.net.ws.WSClient def proxy = new WSClient(“http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl?”, this.class.classLoader) def req = proxy.create(“com.amazon.webservices.awsecommerceservice._2008_04_07.ItemSearchRequest”) req.searchIndex = ‘Books’ req.keywords = “Groovy and Grails” def search = proxy.create(“com.amazon.webservices.awsecommerceservice._2008_04_07.ItemSearch”) search.AWSAccessKeyId = “your id here” search.request.add(req) def res = proxy.ItemSearch(search) res.getItems().each {it.getItem().each { println it.getASIN() }}

If you’ve downloaded the GroovyWS jar and put it in your GROOVY_HOME/lib, that should work. I think it is kinda cool how quick and easy it is you can get something simple working with GroovyWS, but if you are going to be using Amazon Web Services a lot, it is probably easier to grab the Java Library that Amazon provides and use it. Here is the code for using that in Groovy:

import com.amazonaws.a2s.model.*; import com.amazonaws.a2s.*; class AmazonSearch { String key = ‘your key’ String tag = ‘your associates tag’ def doSearch(String keywords) { AmazonA2S service = new AmazonA2SClient(key, tag) ItemSearchRequest request = new ItemSearchRequest() request.searchIndex = ‘Books’ request.keywords = keywords processRequest(service, request) } private processRequest(AmazonA2S service, ItemSearchRequest request) { ItemSearchResponse response = service.itemSearch(request) response.getItems()[0].getItem().each { println it.getASIN() } } static void main(args) { AmazonSearch search = new AmazonSearch() search.doSearch(“Groovy and Grails”) } }