Created
August 29, 2014 02:44
-
-
Save shaon/ad660e6543745268f84e to your computer and use it in GitHub Desktop.
Basic SET/GET/DELETE operations for Bucket Tagging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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