메뉴
Amazon Simple Storage Service
개발자 안내서 (API 버전 2006-03-01)

AWS SDK for Java를 사용하여 교차 리전 복제 설정

서로 다른 두 AWS 계정이 원본과 대상 버킷을 소유한 경우, AWS CLI나 AWS SDK 중 하나를 사용해 원본 버킷에 복제 구성을 추가할 수 있습니다. 원본 버킷에 복제 구성을 추가하면 다른 AWS 계정 소유의 대상 버킷을 지정할 방법이 없기 때문에 콘솔로는 복제 구성을 추가할 수 없습니다. 자세한 내용은 교차 리전 복제 설정 단원을 참조하십시오.

다음 예에서는 버킷에 복제 구성을 추가한 후 해당 구성을 검색 및 확인합니다. 실제 예제를 작성 및 테스트하는 방법에 대한 자세한 내용은 Amazon S3 Java 코드 예제 테스트 단원을 참조하십시오.

import java.io.IOException; import java.util.HashMap; import java.util.Map; import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.model.BucketReplicationConfiguration; import com.amazonaws.services.s3.model.ReplicationDestinationConfig; import com.amazonaws.services.s3.model.ReplicationRule; import com.amazonaws.services.s3.model.ReplicationRuleStatus; import com.amazonaws.services.s3.model.StorageClass; public class CrossRegionReplication { public static void main(String[] args) throws IOException { String clientRegion = "*** Client 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; try { AmazonS3 s3Client = AmazonS3ClientBuilder.standard() .withCredentials(new ProfileCredentialsProvider()) .withRegion(clientRegion) .build(); // Create the replication rule. Map<String, ReplicationRule> replicationRules = new HashMap<String, ReplicationRule>(); replicationRules.put("ReplicationRule1", new ReplicationRule() .withStatus(ReplicationRuleStatus.Enabled) .withPrefix(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 source-bucket replication rule prefix: " + rule.getPrefix()); 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(); } } }

교차 리전 복제(CRR)

교차 리전 복제 설정

이 페이지에서: