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

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

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

다음은 버킷에 복제 구성을 추가한 다음 해당 구성을 검색하는 AWS SDK for Java 코드에 대한 예입니다. 사용자의 버킷 이름과 IAM 역할 ARN을 제공해 코드를 업데이트해야 합니다. 실제 예제를 작성하여 테스트하는 방법에 대한 자세한 내용은 Java 코드 예제 테스트를 참조하십시오.

Copy
import java.io.IOException; import java.util.HashMap; import java.util.Map; import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; 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; public class CrossRegionReplicationComplete { private static String sourceBucketName = "source-bucket"; private static String roleARN = "arn:aws:iam::account-id:role/role-name"; private static String destinationBucketArn = "arn:aws:s3:::destination-bucket"; public static void main(String[] args) throws IOException { AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider()); try { Map<String, ReplicationRule> replicationRules = new HashMap<String, ReplicationRule>(); replicationRules.put( "a-sample-rule-id", new ReplicationRule() .withPrefix("Tax/") .withStatus(ReplicationRuleStatus.Enabled) .withDestinationConfig( new ReplicationDestinationConfig() .withBucketARN(destinationBucketArn) .withStorageClass(StorageClass.Standard_Infrequently_Accessed) ) ); s3Client.setBucketReplicationConfiguration( sourceBucketName, new BucketReplicationConfiguration() .withRoleARN(roleARN) .withRules(replicationRules) ); BucketReplicationConfiguration replicationConfig = s3Client.getBucketReplicationConfiguration(sourceBucketName); ReplicationRule rule = replicationConfig.getRule("a-sample-rule-id"); System.out.println("Destination Bucket ARN : " + rule.getDestinationConfig().getBucketARN()); System.out.println("Prefix : " + rule.getPrefix()); System.out.println("Status : " + rule.getStatus()); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which" + " means your request made it " + "to Amazon S3, but was rejected with an error response" + " for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means"+ " the client encountered " + "a serious internal problem while trying to " + "communicate with Amazon S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } } }

교차 리전 복제(CRR)

교차 리전 복제 설정

이 페이지에서: