AWS Developer Tools Blog
Amazon S3 Requester Pays
You may have heard about the Requester Pays feature in Amazon S3 that allows bucket owners to pass the data transfer costs to users who download the data. Users can now use the AWS SDK for Java to enable/disable Requester Pays on their buckets.
To enable Requester Pays on an Amazon S3 bucket
// create a new AmazonS3 client.
AmazonS3 s3 = new AmazonS3Client();
// call enableRequesterPays method with the bucket name.
s3.enableRequesterPays(bucketName);
To disable Requester Pays on an Amazon S3 bucket
// create a new AmazonS3 client
AmazonS3 s3 = new AmazonS3Client();
// call disableRequesterPays method with the bucket name
s3.disableRequesterPays(bucketName);
In addition, the AWS SDK for Java also allows users to download data from a Requester Pays bucket. The following example shows how easy it is:
// create a new AmazonS3 client
AmazonS3 s3 = new AmazonS3Client();
// The requester pays flag must be set to true for accessing an Amazon S3 bucket that has requester pays enabled
// Otherwise, Amazon S3 would respond with an Access Denied exception.
// The isRequesterPays flag is explicitly set to acknowledge that the requester knows he or she will be charged for the download.
boolean isRequesterPays = true;
S3Object object = s3.getObject(new GetObjectRequest(bucketName,key,isRequesterPays));
Are you using the AWS SDK for Java to access Amazon S3? Let us know your experience.