Skip to content

Instantly share code, notes, and snippets.

@shaon
Created August 29, 2014 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaon/ad660e6543745268f84e to your computer and use it in GitHub Desktop.
Save shaon/ad660e6543745268f84e to your computer and use it in GitHub Desktop.
Basic SET/GET/DELETE operations for Bucket Tagging
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.BucketTaggingConfiguration;
import com.amazonaws.services.s3.model.TagSet;
import java.util.ArrayList;
import java.util.List;
public class BucketTaggingTest {
public static void main( String[] args ) {
AmazonS3 s3Client = new AmazonS3Client( new BasicAWSCredentials( "AKIIG8QOSNPYF6FRBCCB", "fRT7KPSmHumOrEINsbcBG7hCNbuPVJdDqfeve9IL" ) );
s3Client.setEndpoint( "http://10.111.5.146:8773/services/objectstorage" );
String bucketName = "testbucket";
Bucket bucket = s3Client.createBucket( bucketName );
TagSet tagSet = new TagSet( );
tagSet.setTag( "testkey1", "testvalue1");
tagSet.setTag( "testkey2", "testvalue2");
List<TagSet> tagSetList = new ArrayList<TagSet>( );
tagSetList.add( tagSet );
BucketTaggingConfiguration taggingConfiguration = new BucketTaggingConfiguration( );
taggingConfiguration.setTagSets( tagSetList );
s3Client.setBucketTaggingConfiguration( bucket.getName(), taggingConfiguration );
List<TagSet> resultTagSet = s3Client.getBucketTaggingConfiguration( bucket.getName( ) ).getAllTagSets( );
for ( TagSet tag : resultTagSet ) {
System.out.println( "Tags for bucket '" + bucket.getName( ) + "' are: " + tag.getAllTags( ) );
}
s3Client.deleteBucketTaggingConfiguration( bucket.getName( ) );
s3Client.deleteBucket( bucket.getName( ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment