Reputation: 31
I am working with Amazon S3 and I need to parse the Amazon S3 bucket name and object key from the object ARN by using Java. Is there any built-in library for it? if not can you help me with the java code for it.
Upvotes: 1
Views: 2564
Reputation: 10704
The Amazon S3 API does not have an API method for this. You can use Java logic to obtain the bucket name and object name from an Object ARN. Here is your solution.
String arn = "arn:aws:s3:::bucketmay10002/book.pdf";
String bucketObject = "";
String[] value1 = arn.split(":::");
for (String t : value1){
bucketObject = t ;
System.out.println(bucketObject);
}
String[] value3 = bucketObject.split("/");
for (String t : value3)
System.out.println(t);
}
Output:
As you can see, you get both the bucket name and object name from the given object ARN.
Upvotes: 1