use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class GetBucketPolicy method getPolicy.
// snippet-start:[s3.java2.get_bucket_policy.main]
public static String getPolicy(S3Client s3, String bucketName) {
String policyText = "";
System.out.format("Getting policy for bucket: \"%s\"\n\n", bucketName);
GetBucketPolicyRequest policyReq = GetBucketPolicyRequest.builder().bucket(bucketName).build();
try {
GetBucketPolicyResponse policyRes = s3.getBucketPolicy(policyReq);
policyText = policyRes.policy();
return policyText;
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class GetObjectData method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <bucketName> <keyName> <path>\n\n" + "Where:\n" + " bucketName - the Amazon S3 bucket name. \n\n" + " keyName - the key name. \n\n" + " path - the path where the file is written to. \n\n";
if (args.length != 3) {
System.out.println(USAGE);
System.exit(1);
}
String bucketName = args[0];
String keyName = args[1];
String path = args[2];
Region region = Region.US_EAST_1;
S3Client s3 = S3Client.builder().region(region).build();
getObjectBytes(s3, bucketName, keyName, path);
s3.close();
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class GetObjectTags method listTags.
// snippet-start:[s3.java2.getobjecttags.main]
public static void listTags(S3Client s3, String bucketName, String keyName) {
try {
GetObjectTaggingRequest getTaggingRequest = GetObjectTaggingRequest.builder().key(keyName).bucket(bucketName).build();
GetObjectTaggingResponse tags = s3.getObjectTagging(getTaggingRequest);
List<Tag> tagSet = tags.tagSet();
// Write out the tags
Iterator<Tag> tagIterator = tagSet.iterator();
while (tagIterator.hasNext()) {
Tag tag = (Tag) tagIterator.next();
System.out.println(tag.key());
System.out.println(tag.value());
}
} catch (S3Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class ListMultipartUploads method listUploads.
// snippet-start:[s3.java2.list_multi_uploads.main]
public static void listUploads(S3Client s3, String bucketName) {
try {
ListMultipartUploadsRequest listMultipartUploadsRequest = ListMultipartUploadsRequest.builder().bucket(bucketName).build();
ListMultipartUploadsResponse response = s3.listMultipartUploads(listMultipartUploadsRequest);
List<MultipartUpload> uploads = response.uploads();
for (MultipartUpload upload : uploads) {
System.out.println("Upload in progress: Key = \"" + upload.key() + "\", id = " + upload.uploadId());
}
} catch (S3Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.s3.S3Client in project aws-doc-sdk-examples by awsdocs.
the class ManagingObjectTags method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " <bucketName> <objectKey> <objectPath> \n\n" + "Where:\n" + " bucketName - the Amazon S3 bucket.\n" + " objectKey - the object that a tag is applied (for example, book.pdf).\n" + " objectPath - the path where the file is located (for example, C:/AWS/book2.pdf). \n\n";
if (args.length != 3) {
System.out.println(USAGE);
System.exit(1);
}
String bucketName = args[0];
String objectKey = args[1];
String objectPath = args[2];
System.out.println("Putting object " + objectKey + " into bucket " + bucketName);
System.out.println(" in bucket: " + bucketName);
Region region = Region.US_EAST_1;
S3Client s3 = S3Client.builder().region(region).build();
putS3ObjectTags(s3, bucketName, objectKey, objectPath);
updateObjectTags(s3, bucketName, objectKey);
s3.close();
}
Aggregations