Client will send a S3 object URL(ARN) using my API. The object is a JSON file. How to access the object using ARN using java
Asked
Active
Viewed 1,047 times
1
-
3An S3 object ARN, if that's what you have, includes both the bucket name and object key. Parse those out of the ARN and then use the AWS Java SDK to access the S3 object. – jarmod Jun 02 '21 at 12:26
1 Answers
0
You can retrieve the bucket name and the object name from the JSON and use these values to get the object. For example, assume you want to read the byte[] of the object. Using the Amazon S3 Java API V2, you can perform this use case:
public static void getObjectBytes (S3Client s3, String bucketName, String keyName, String path ) {
GetObjectRequest objectRequest = GetObjectRequest
.builder()
.key(keyName)
.bucket(bucketName)
.build();
ResponseBytes<GetObjectResponse> objectBytes = s3.getObjectAsBytes(objectRequest);
byte[] data = objectBytes.asByteArray();
// more logic
}

smac2020
- 9,637
- 4
- 24
- 38