-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS3tools_mctp.java
60 lines (41 loc) · 1.47 KB
/
S3tools_mctp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package benWhitesharkPkg;
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
public class S3tools_mctp {
private AmazonS3 s3Client;
private AWSCredentials credentials;
private boolean isCredentials;
public void initialise() {
//assumes relying on iam role attached to ec2 instance to provide credentials
s3Client = new AmazonS3Client();
}
public void initialise(String userAtAccount) {
try {
try {
this.credentials = new ProfileCredentialsProvider(userAtAccount).getCredentials();
this.isCredentials = true;
} catch (Exception e) {
isCredentials = false;
throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
+ "Please make sure that your credentials file is at the correct "
+ "location (C:\\Users\\Ben\\.aws\\credentials), and is in valid format.", e);
}
} catch (Exception e2) {
isCredentials = false;
}
if (this.isCredentials == true) {
s3Client = new AmazonS3Client(credentials);
} else {
s3Client = new AmazonS3Client();
}
}
public String downloadJsonString(String bucket, String key) {
return s3Client.getObjectAsString(bucket, key);
}
public void uploadJsonString(String bucket,String key,String jsonStr) {
s3Client.putObject(bucket, key, jsonStr);
}
}