Search in sources :

Example 16 with Delete

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

the class LifecycleConfiguration method deleteLifecycleConfig.

// Delete the configuration from the Amazon S3 bucket.
public static void deleteLifecycleConfig(S3Client s3, String bucketName, String accountId) {
    try {
        DeleteBucketLifecycleRequest deleteBucketLifecycleRequest = DeleteBucketLifecycleRequest.builder().bucket(bucketName).expectedBucketOwner(accountId).build();
        s3.deleteBucketLifecycle(deleteBucketLifecycleRequest);
    } catch (S3Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) DeleteBucketLifecycleRequest(software.amazon.awssdk.services.s3.model.DeleteBucketLifecycleRequest)

Example 17 with Delete

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

the class DeleteBucketPolicy method main.

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

Example 18 with Delete

use of software.amazon.awssdk.services.s3.model.Delete in project beam by apache.

the class S3FileSystemTest method deleteThousandsOfObjectsInMultipleBuckets.

@Test
public void deleteThousandsOfObjectsInMultipleBuckets() throws IOException {
    S3FileSystem s3FileSystem = buildMockedS3FileSystem(s3Config("s3"));
    List<String> buckets = ImmutableList.of("bucket1", "bucket2");
    List<String> keys = new ArrayList<>();
    for (int i = 0; i < 2500; i++) {
        keys.add(String.format("key-%d", i));
    }
    List<S3ResourceId> paths = new ArrayList<>();
    for (String bucket : buckets) {
        for (String key : keys) {
            paths.add(S3ResourceId.fromComponents("s3", bucket, key));
        }
    }
    s3FileSystem.delete(paths);
    // Should require 6 calls to delete 2500 objects in each of 2 buckets.
    verify(s3FileSystem.getS3Client(), times(6)).deleteObjects(any(DeleteObjectsRequest.class));
}
Also used : ArrayList(java.util.ArrayList) S3TestUtils.buildMockedS3FileSystem(org.apache.beam.sdk.io.aws2.s3.S3TestUtils.buildMockedS3FileSystem) DeleteObjectsRequest(software.amazon.awssdk.services.s3.model.DeleteObjectsRequest) Test(org.junit.Test)

Example 19 with Delete

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

the class S3SinkTest method deleteObjects.

@AfterClass
public static void deleteObjects() {
    S3Client client = client();
    List<ObjectIdentifier> identifiers = listObjects(client).contents().stream().map(S3Object::key).map(key -> ObjectIdentifier.builder().key(key).build()).collect(Collectors.toList());
    if (!identifiers.isEmpty()) {
        client.deleteObjects(b -> b.bucket(BUCKET).delete(d -> d.objects(identifiers)));
    }
    int sleepMillis = (int) (SECONDS.toMillis(WAIT_AFTER_CLEANUP_IN_SECS) / 10);
    long deadline = System.currentTimeMillis() + SECONDS.toMillis(WAIT_AFTER_CLEANUP_IN_SECS);
    int keyCount;
    while ((keyCount = listObjects(client).keyCount()) != 0 && System.currentTimeMillis() < deadline) {
        logger.info("After sending the object cleanup request to S3, the bucket, " + BUCKET + ", still has " + keyCount + " keys.");
        sleepMillis(sleepMillis);
    }
    if (keyCount == 0) {
        logger.info("We finished waiting because we observe that the keys were deleted.");
    } else {
        logger.warning("There may still be keys in the bucket that are not deleted.\n" + "At our last check, keyCount was " + keyCount + "\n We finished waiting because of the timeout.");
    }
}
Also used : Logger(com.hazelcast.logging.Logger) NightlyTest(com.hazelcast.test.annotation.NightlyTest) AfterClass(org.junit.AfterClass) S3Client(software.amazon.awssdk.services.s3.S3Client) S3Object(software.amazon.awssdk.services.s3.model.S3Object) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) ListObjectsV2Request(software.amazon.awssdk.services.s3.model.ListObjectsV2Request) Category(org.junit.experimental.categories.Category) ListObjectsV2Response(software.amazon.awssdk.services.s3.model.ListObjectsV2Response) Collectors(java.util.stream.Collectors) SupplierEx(com.hazelcast.function.SupplierEx) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) List(java.util.List) ILogger(com.hazelcast.logging.ILogger) ObjectIdentifier(software.amazon.awssdk.services.s3.model.ObjectIdentifier) Region(software.amazon.awssdk.regions.Region) SECONDS(java.util.concurrent.TimeUnit.SECONDS) S3Object(software.amazon.awssdk.services.s3.model.S3Object) S3Client(software.amazon.awssdk.services.s3.S3Client) ObjectIdentifier(software.amazon.awssdk.services.s3.model.ObjectIdentifier) AfterClass(org.junit.AfterClass)

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