2016-06-21 2 views
3

S3 버킷의 객체 복사에 대한 REST 기반 액세스에 대한 현재 코드가 작동하지 않습니다. 내 S3 버킷은 https 액세스를 위해 구성되었으며 sse를 사용할 수 있습니다. 작동 시키려면 아래 코드를 어떻게 수정해야합니까? 현재 'AmazonClientException을 발견했습니다.'라는 오류 메시지가 표시됩니다. 이는 네트워크에 액세스 할 수없는 것과 같이 클라이언트가 S3과 통신하는 동안 오류가 발생했음을 의미합니다. mybucket.s3.amazonaws.com '를 해결https 연결을 사용하는 Amazon S3 SDK

@PUT 
    @Path("/copy/{bucketName}") 
    public void copyObject(@PathParam("bucketName") String bucketName, @QueryParam("fromPath") String fromPath, 
      @QueryParam("toPath") String toPath) throws AmazonClientException { 

     AmazonS3 s3client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain()); 
     try { 

      CopyObjectRequest copyObjRequest = new CopyObjectRequest(bucketName, fromPath, bucketName, toPath); 
      System.out.println("Copying object."); 

      s3client.copyObject(copyObjRequest); 

     } 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 " 
        + "an internal error while trying to " + " communicate with S3, " 
        + "such as not being able to access the network."); 
      System.out.println("Error Message: " + ace.getMessage()); 
     } 
    } 
+0

사용중인 SDK 및 버전은 무엇입니까? – error2007s

+0

양동이에 버킷 이름에 점이 없습니까? –

답변

2

: 오류 메시지 : HTTP 요청을 실행할 수 없습니다. 결국 프록시 문제가되었습니다. 나는 이것을 극복하기 위해 다음을해야했다. 네트워크 문제를 극복 할 때 S3 Endpoint를 설정하라는 또 다른 예외가있었습니다. 아래 코드가 변경됩니다.

public static final String PROXY_HOST = "<my proxy hostname>"; 
public static final int PROXY_PORT = <my_proxy_port>; 
public static final String S3_ENDPOINT = "https://s3.amazonaws.com"; 

ClientConfiguration clientCfg = new ClientConfiguration(); 
clientCfg.setProtocol(Protocol.HTTP); 
clientCfg.setProxyHost(PROXY_HOST); 
clientCfg.setProxyPort(PROXY_PORT); 

AmazonS3 s3Client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain(), clientCfg); 

s3Client.setEndpoint(S3_ENDPOINT); 
s3Client.setRegion(Region.getRegion(Regions.US_EAST_1)); 
+1

에 솔루션이 포함되어 있으므로이 질문에 대답이없는 것으로 나타나지 않도록 직접 대답을 수락하는 것이 좋습니다. –