use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project jackrabbit-oak by apache.
the class Utils method deleteBucket.
/**
* Delete S3 bucket. This method first deletes all objects from bucket and
* then delete empty bucket.
*
* @param bucketName the bucket name.
*/
public static void deleteBucket(final String bucketName) throws IOException {
Properties prop = readConfig(DEFAULT_CONFIG_FILE);
AmazonS3 s3service = openService(prop);
ObjectListing prevObjectListing = s3service.listObjects(bucketName);
while (true) {
for (S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
s3service.deleteObject(bucketName, s3ObjSumm.getKey());
}
if (!prevObjectListing.isTruncated()) {
break;
}
prevObjectListing = s3service.listNextBatchOfObjects(prevObjectListing);
}
s3service.deleteBucket(bucketName);
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project components by Talend.
the class S3Connection method createClient.
public static AmazonS3 createClient(S3OutputProperties properties) {
S3DatasetProperties data_set = properties.getDatasetProperties();
S3DatastoreProperties data_store = properties.getDatasetProperties().getDatastoreProperties();
com.amazonaws.auth.AWSCredentials credentials = new com.amazonaws.auth.BasicAWSCredentials(data_store.accessKey.getValue(), data_store.secretKey.getValue());
Region region = RegionUtils.getRegion(data_set.region.getValue().getValue());
Boolean clientSideEnc = data_set.encryptDataInMotion.getValue();
AmazonS3 conn = null;
if (clientSideEnc != null && clientSideEnc) {
String kms_cmk = data_set.kmsForDataInMotion.getValue();
KMSEncryptionMaterialsProvider encryptionMaterialsProvider = new KMSEncryptionMaterialsProvider(kms_cmk);
conn = new AmazonS3EncryptionClient(credentials, encryptionMaterialsProvider, new CryptoConfiguration().withAwsKmsRegion(region));
} else {
AWSCredentialsProvider basicCredentialsProvider = new StaticCredentialsProvider(credentials);
conn = new AmazonS3Client(basicCredentialsProvider);
}
conn.setRegion(region);
return conn;
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project components by Talend.
the class S3SinkTestIT method testAction.
@Test
public void testAction() throws IOException {
S3OutputProperties properties = PropertiesPreparer.createS3OtuputProperties();
runtime.initialize(null, properties);
S3WriteOperation writeOperation = runtime.createWriteOperation();
S3OutputWriter writer = writeOperation.createWriter(null);
writer.open("u001");
Schema schema = PropertiesPreparer.createTestSchema();
IndexedRecord r1 = new GenericData.Record(schema);
r1.put(0, 1);
r1.put(1, "wangwei");
writer.write(r1);
IndexedRecord r2 = new GenericData.Record(schema);
r2.put(0, 2);
r2.put(1, "gaoyan");
writer.write(r2);
IndexedRecord r3 = new GenericData.Record(schema);
r3.put(0, 3);
r3.put(1, "dabao");
writer.write(r3);
writer.close();
AmazonS3 s3_client = S3Connection.createClient(properties);
String data = s3_client.getObjectAsString(PropertiesPreparer.bucket, PropertiesPreparer.objectkey);
String expect = "ID;NAME1;wangwei2;gaoyan3;dabao";
org.junit.Assert.assertEquals("data content is not right", expect, data.replaceAll("[\r\n]+", ""));
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project components by Talend.
the class S3SinkTestIT method after.
@After
public void after() {
AmazonS3 s3_client = S3Connection.createClient(PropertiesPreparer.createS3OtuputProperties());
s3_client.deleteObject(PropertiesPreparer.bucket, PropertiesPreparer.objectkey);
}
use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project testcontainers-java by testcontainers.
the class SimpleLocalstackS3Test method s3Test.
@Test
public void s3Test() throws IOException {
AmazonS3 s3 = AmazonS3ClientBuilder.standard().withEndpointConfiguration(localstack.getEndpointConfiguration(S3)).withCredentials(localstack.getDefaultCredentialsProvider()).build();
s3.createBucket("foo");
s3.putObject("foo", "bar", "baz");
final List<Bucket> buckets = s3.listBuckets();
assertEquals("The created bucket is present", 1, buckets.size());
final Bucket bucket = buckets.get(0);
assertEquals("The created bucket has the right name", "foo", bucket.getName());
assertEquals("The created bucket has the right name", "foo", bucket.getName());
final ObjectListing objectListing = s3.listObjects("foo");
assertEquals("The created bucket has 1 item in it", 1, objectListing.getObjectSummaries().size());
final S3Object object = s3.getObject("foo", "bar");
final String content = IOUtils.toString(object.getObjectContent(), Charset.forName("UTF-8"));
assertEquals("The object can be retrieved", "baz", content);
}
Aggregations