use of com.amazonaws.services.s3.model.DeleteMarkerReplication in project aws-doc-sdk-examples by awsdocs.
the class CrossRegionReplication method main.
public static void main(String[] args) throws IOException {
Regions clientRegion = Regions.DEFAULT_REGION;
String accountId = "*** Account ID ***";
String roleName = "*** Role name ***";
String sourceBucketName = "*** Source bucket name ***";
String destBucketName = "*** Destination bucket name ***";
String prefix = "Tax/";
String roleARN = String.format("arn:aws:iam::%s:role/%s", accountId, roleName);
String destinationBucketARN = "arn:aws:s3:::" + destBucketName;
AmazonS3 s3Client = AmazonS3Client.builder().withCredentials(new ProfileCredentialsProvider()).withRegion(clientRegion).build();
createBucket(s3Client, clientRegion, sourceBucketName);
createBucket(s3Client, clientRegion, destBucketName);
assignRole(roleName, clientRegion, sourceBucketName, destBucketName);
try {
// Create the replication rule.
List<ReplicationFilterPredicate> andOperands = new ArrayList<ReplicationFilterPredicate>();
andOperands.add(new ReplicationPrefixPredicate(prefix));
Map<String, ReplicationRule> replicationRules = new HashMap<String, ReplicationRule>();
replicationRules.put("ReplicationRule1", new ReplicationRule().withPriority(0).withStatus(ReplicationRuleStatus.Enabled).withDeleteMarkerReplication(new DeleteMarkerReplication().withStatus(DeleteMarkerReplicationStatus.DISABLED)).withFilter(new ReplicationFilter().withPredicate(new ReplicationPrefixPredicate(prefix))).withDestinationConfig(new ReplicationDestinationConfig().withBucketARN(destinationBucketARN).withStorageClass(StorageClass.Standard)));
// Save the replication rule to the source bucket.
s3Client.setBucketReplicationConfiguration(sourceBucketName, new BucketReplicationConfiguration().withRoleARN(roleARN).withRules(replicationRules));
// Retrieve the replication configuration and verify that the configuration
// matches the rule we just set.
BucketReplicationConfiguration replicationConfig = s3Client.getBucketReplicationConfiguration(sourceBucketName);
ReplicationRule rule = replicationConfig.getRule("ReplicationRule1");
System.out.println("Retrieved destination bucket ARN: " + rule.getDestinationConfig().getBucketARN());
System.out.println("Retrieved priority: " + rule.getPriority());
System.out.println("Retrieved source-bucket replication rule status: " + rule.getStatus());
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.
e.printStackTrace();
} catch (SdkClientException e) {
// Amazon S3 couldn't be contacted for a response, or the client
// couldn't parse the response from Amazon S3.
e.printStackTrace();
}
}
Aggregations