Search in sources :

Example 56 with S3Client

use of uk.co.automatictester.lightning.lambda.s3.S3Client 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 57 with S3Client

use of uk.co.automatictester.lightning.lambda.s3.S3Client in project aws-doc-sdk-examples by awsdocs.

the class S3BucketOps method main.

public static void main(String[] args) {
    // snippet-start:[s3.java2.s3_bucket_ops.region]
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder().region(region).build();
    // snippet-end:[s3.java2.s3_bucket_ops.region]
    String bucket = "bucket" + System.currentTimeMillis();
    System.out.println(bucket);
    createBucket(s3, bucket);
    performOperations(s3, bucket);
}
Also used : Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 58 with S3Client

use of uk.co.automatictester.lightning.lambda.s3.S3Client in project aws-doc-sdk-examples by awsdocs.

the class S3Log method main.

public static void main(String[] args) {
    System.out.println("testing logging setup for " + S3Log.class);
    Region region = Region.US_WEST_2;
    S3Client s3 = S3Client.builder().region(region).build();
    ListBucketsRequest listBucketsRequest = ListBucketsRequest.builder().build();
    ListBucketsResponse listBucketsResponse = s3.listBuckets(listBucketsRequest);
    listBucketsResponse.buckets().stream().forEach(x -> System.out.println(x.name()));
    logger.info("logging level info");
    logger.debug("logging debug stuff");
    logger.warn("logging warning");
    logger.error("logging error");
    logger.fatal("logging fatal");
}
Also used : ListBucketsResponse(software.amazon.awssdk.services.s3.model.ListBucketsResponse) ListBucketsRequest(software.amazon.awssdk.services.s3.model.ListBucketsRequest) Region(software.amazon.awssdk.regions.Region) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 59 with S3Client

use of uk.co.automatictester.lightning.lambda.s3.S3Client in project hazelcast by hazelcast.

the class S3MockTest method when_itemsToSinkIsLargerThanBuffer.

@Test
public void when_itemsToSinkIsLargerThanBuffer() {
    s3Client.createBucket(b -> b.bucket(SINK_BUCKET));
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < S3SinkContext.DEFAULT_MINIMUM_UPLOAD_PART_SIZE / 5; i++) {
        sb.append("01234567890");
    }
    String expected = sb.toString();
    Pipeline p = Pipeline.create();
    p.readFrom(TestSources.items(expected)).writeTo(S3Sinks.s3(SINK_BUCKET, null, UTF_8, clientSupplier(), Object::toString));
    hz.getJet().newJob(p).join();
    try (S3Client client = clientSupplier().get()) {
        List<String> lines = client.listObjectsV2(req -> req.bucket(SINK_BUCKET)).contents().stream().peek(o -> System.out.println("Found object: " + o)).map(object -> client.getObject(req -> req.bucket(SINK_BUCKET).key(object.key()), toInputStream())).flatMap(this::inputStreamToLines).collect(Collectors.toList());
        assertEquals(1, lines.size());
        String actual = lines.get(0);
        assertEquals(expected.length(), actual.length());
        assertEquals(expected, actual);
    }
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) System.lineSeparator(java.lang.System.lineSeparator) BeforeClass(org.junit.BeforeClass) IntStream.range(java.util.stream.IntStream.range) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ArrayList(java.util.ArrayList) ILogger(com.hazelcast.logging.ILogger) After(org.junit.After) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) Before(org.junit.Before) Logger(com.hazelcast.logging.Logger) AfterClass(org.junit.AfterClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) S3Client(software.amazon.awssdk.services.s3.S3Client) UTF_8(java.nio.charset.StandardCharsets.UTF_8) S3SinkContext(com.hazelcast.jet.s3.S3Sinks.S3SinkContext) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) SupplierEx(com.hazelcast.function.SupplierEx) IgnoreInJenkinsOnWindows(com.hazelcast.jet.test.IgnoreInJenkinsOnWindows) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) ResponseTransformer.toInputStream(software.amazon.awssdk.core.sync.ResponseTransformer.toInputStream) RequestBody(software.amazon.awssdk.core.sync.RequestBody) DockerClientFactory(org.testcontainers.DockerClientFactory) Assume.assumeTrue(org.junit.Assume.assumeTrue) Assert.assertEquals(org.junit.Assert.assertEquals) S3Client(software.amazon.awssdk.services.s3.S3Client) Pipeline(com.hazelcast.jet.pipeline.Pipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 60 with S3Client

use of uk.co.automatictester.lightning.lambda.s3.S3Client 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

S3Client (software.amazon.awssdk.services.s3.S3Client)63 Region (software.amazon.awssdk.regions.Region)43 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)8 S3Object (software.amazon.awssdk.services.s3.model.S3Object)7 List (java.util.List)5 GetObjectRequest (software.amazon.awssdk.services.s3.model.GetObjectRequest)5 GetObjectResponse (software.amazon.awssdk.services.s3.model.GetObjectResponse)5 SupplierEx (com.hazelcast.function.SupplierEx)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)3 S3ClientBuilder (software.amazon.awssdk.services.s3.S3ClientBuilder)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)2 TestSources (com.hazelcast.jet.pipeline.test.TestSources)2 ILogger (com.hazelcast.logging.ILogger)2 Logger (com.hazelcast.logging.Logger)2 HazelcastSerialClassRunner (com.hazelcast.test.HazelcastSerialClassRunner)2 Collectors (java.util.stream.Collectors)2 AfterClass (org.junit.AfterClass)2 Test (org.junit.Test)2