· 7 years ago · May 11, 2018, 10:14 AM
1public class AWSTest {
2
3 static String ACCESS_KEY = "...";
4 static String SECRET_KEY = "...";
5 static String BUCKET = "...";
6 static String OBJECT_KEY = "...";
7
8 public static void main(String[] args) throws IOException {
9 aws();
10 }
11
12 public static void aws() throws IOException {
13 BasicAWSCredentials awsCreds = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
14 AmazonS3 s3 = AmazonS3ClientBuilder.standard()
15 .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
16 .withRegion("us-east-1")
17 .build();
18
19 try (S3Object object = s3.getObject(BUCKET, OBJECT_KEY)) {
20 String json = readString(object.getObjectContent());
21
22 System.out.println(json);
23 }
24 }
25
26 private static String readString(InputStream is) throws IOException {
27 return StreamUtils.copyToString(is, StandardCharsets.UTF_8);
28 }
29}