forked from yukuansong-uscis/aws-codeguru-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample3.java
More file actions
33 lines (30 loc) · 1.34 KB
/
Sample3.java
File metadata and controls
33 lines (30 loc) · 1.34 KB
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
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
public class Sample3 {
public String accessKeyId="AERWERWRSDFASDFER3SFP";
public String secretAccessKey="asdffkl4rfdvgf+3xcfa23sdfdsfDASFNSFSDDF";
public boolean getS3BucketExists() {
AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, secretAccessKey);
AmazonS3 s3client = AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.withRegion(Regions.US_EAST_1)
.build();
return s3client.doesBucketExist("mytestBucket");
}
public void restoreS3Pbject() {
AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, secretAccessKey);
AmazonS3 s3client = AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.withRegion(Regions.US_EAST_1)
.build();
String key="testfile";
String bucketName="mytestbucket";
s3client.restoreObject( bucketName, key, 20);
}
}