Search in sources :

Example 11 with Delete

use of software.amazon.awssdk.services.s3.model.Delete in project ddf by codice.

the class DeleteBean method delete.

public void delete(@Header(AWS2S3Constants.KEY) String s3Key) {
    LOGGER.trace("Deleting: {} / {}", s3Bucket, s3Key);
    ArrayList<ObjectIdentifier> toDelete = new ArrayList<>();
    toDelete.add(ObjectIdentifier.builder().key(s3Key).build());
    DeleteObjectsRequest deleteRequest = DeleteObjectsRequest.builder().bucket(s3Bucket).delete(Delete.builder().objects(toDelete).build()).build();
    s3Client.deleteObjects(deleteRequest);
}
Also used : ArrayList(java.util.ArrayList) ObjectIdentifier(software.amazon.awssdk.services.s3.model.ObjectIdentifier) DeleteObjectsRequest(software.amazon.awssdk.services.s3.model.DeleteObjectsRequest)

Example 12 with Delete

use of software.amazon.awssdk.services.s3.model.Delete in project aws-doc-sdk-examples by awsdocs.

the class DeleteWebsiteConfiguration method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "   <bucketName>\n\n" + "Where:\n" + "   bucketName - the Amazon S3 bucket to delete the website configuration from.\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    System.out.format("Deleting website configuration for Amazon S3 bucket: %s\n", bucketName);
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder().region(region).build();
    deleteBucketWebsiteConfig(s3, bucketName);
    System.out.println("Done!");
    s3.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 13 with Delete

use of software.amazon.awssdk.services.s3.model.Delete in project aws-doc-sdk-examples by awsdocs.

the class S3Service method deleteTagFromObject.

// Delete tags from the given object.
public void deleteTagFromObject(String bucketName, String key) {
    try {
        DeleteObjectTaggingRequest deleteObjectTaggingRequest = DeleteObjectTaggingRequest.builder().key(key).bucket(bucketName).build();
        S3Client s3 = getClient();
        s3.deleteObjectTagging(deleteObjectTaggingRequest);
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DeleteObjectTaggingRequest(software.amazon.awssdk.services.s3.model.DeleteObjectTaggingRequest) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 14 with Delete

use of software.amazon.awssdk.services.s3.model.Delete in project aws-doc-sdk-examples by awsdocs.

the class DeleteObjects method deleteBucketObjects.

// snippet-start:[s3.java2.delete_objects.main]
public static void deleteBucketObjects(S3Client s3, String bucketName, String objectName) {
    ArrayList<ObjectIdentifier> toDelete = new ArrayList<ObjectIdentifier>();
    toDelete.add(ObjectIdentifier.builder().key(objectName).build());
    try {
        DeleteObjectsRequest dor = DeleteObjectsRequest.builder().bucket(bucketName).delete(Delete.builder().objects(toDelete).build()).build();
        s3.deleteObjects(dor);
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) ArrayList(java.util.ArrayList) ObjectIdentifier(software.amazon.awssdk.services.s3.model.ObjectIdentifier) DeleteObjectsRequest(software.amazon.awssdk.services.s3.model.DeleteObjectsRequest)

Example 15 with Delete

use of software.amazon.awssdk.services.s3.model.Delete in project aws-doc-sdk-examples by awsdocs.

the class LifecycleConfiguration method setLifecycleConfig.

// snippet-start:[s3.java2.manage_lifecycle.main]
public static void setLifecycleConfig(S3Client s3, String bucketName, String accountId) {
    try {
        // Create a rule to archive objects with the "glacierobjects/" prefix to Amazon S3 Glacier.
        LifecycleRuleFilter ruleFilter = LifecycleRuleFilter.builder().prefix("glacierobjects/").build();
        Transition transition = Transition.builder().storageClass(TransitionStorageClass.GLACIER).days(0).build();
        LifecycleRule rule1 = LifecycleRule.builder().id("Archive immediately rule").filter(ruleFilter).transitions(transition).status(ExpirationStatus.ENABLED).build();
        // Create a second rule.
        Transition transition2 = Transition.builder().storageClass(TransitionStorageClass.GLACIER).days(0).build();
        List<Transition> transitionList = new ArrayList<>();
        transitionList.add(transition2);
        LifecycleRuleFilter ruleFilter2 = LifecycleRuleFilter.builder().prefix("glacierobjects/").build();
        LifecycleRule rule2 = LifecycleRule.builder().id("Archive and then delete rule").filter(ruleFilter2).transitions(transitionList).status(ExpirationStatus.ENABLED).build();
        // Add the LifecycleRule objects to an ArrayList.
        ArrayList<LifecycleRule> ruleList = new ArrayList<>();
        ruleList.add(rule1);
        ruleList.add(rule2);
        BucketLifecycleConfiguration lifecycleConfiguration = BucketLifecycleConfiguration.builder().rules(ruleList).build();
        PutBucketLifecycleConfigurationRequest putBucketLifecycleConfigurationRequest = PutBucketLifecycleConfigurationRequest.builder().bucket(bucketName).lifecycleConfiguration(lifecycleConfiguration).expectedBucketOwner(accountId).build();
        s3.putBucketLifecycleConfiguration(putBucketLifecycleConfigurationRequest);
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : BucketLifecycleConfiguration(software.amazon.awssdk.services.s3.model.BucketLifecycleConfiguration) LifecycleRuleFilter(software.amazon.awssdk.services.s3.model.LifecycleRuleFilter) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) Transition(software.amazon.awssdk.services.s3.model.Transition) ArrayList(java.util.ArrayList) LifecycleRule(software.amazon.awssdk.services.s3.model.LifecycleRule) PutBucketLifecycleConfigurationRequest(software.amazon.awssdk.services.s3.model.PutBucketLifecycleConfigurationRequest)

Aggregations

S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)10 S3Client (software.amazon.awssdk.services.s3.S3Client)9 ArrayList (java.util.ArrayList)8 Region (software.amazon.awssdk.regions.Region)7 DeleteObjectsRequest (software.amazon.awssdk.services.s3.model.DeleteObjectsRequest)6 ObjectIdentifier (software.amazon.awssdk.services.s3.model.ObjectIdentifier)5 ListObjectsV2Request (software.amazon.awssdk.services.s3.model.ListObjectsV2Request)4 ListObjectsV2Response (software.amazon.awssdk.services.s3.model.ListObjectsV2Response)4 S3Object (software.amazon.awssdk.services.s3.model.S3Object)4 IOException (java.io.IOException)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 CompleteMultipartUploadRequest (software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest)2 CompletedMultipartUpload (software.amazon.awssdk.services.s3.model.CompletedMultipartUpload)2 CompletedPart (software.amazon.awssdk.services.s3.model.CompletedPart)2 CreateMultipartUploadRequest (software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest)2 CreateMultipartUploadResponse (software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse)2 Delete (software.amazon.awssdk.services.s3.model.Delete)2 DeleteBucketRequest (software.amazon.awssdk.services.s3.model.DeleteBucketRequest)2