This works for me:
def aws_credentials = {
return new AWSCredentials(grailsApplication.config.aws.accessKey, grailsApplication.config.aws.secretKey)
}
def s3_service = {
return new RestS3Service(aws_credentials())
}
def test = {
def buckets = s3_service().listAllBuckets()
System.out.println("How many buckets to I have in S3? " + myBuckets.length);
}
And of course you don't have to put the objects in multiple methods, use them however you want.
Also make sure you have these imports:
import org.jets3t.service.impl.rest.httpclient.RestS3Service
import org.jets3t.service.security.AWSCredentials