ListObjectsRequest成功但PutObjectRequest返回403 AccessDenied

时间:2017-12-12 22:52:10

标签: java amazon-s3 http-status-code-403

我有一个ListObjectsRequest方法,它按预期工作,但也有一个PutObjectRequest方法,它返回以下内容:

  

com.amazonaws.shade.services.s3.model.AmazonS3Exception:拒绝访问(服务:Amazon S3;状态代码:403;错误代码:AccessDenied;请求ID:32d91db5-b2b8-496c-9c11-546cb81453fb)     在com.amazonaws.shade.http.AmazonHttpClient $ RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1588)     在com.amazonaws.shade.http.AmazonHttpClient $ RequestExecutor.executeOneRequest(AmazonHttpClient.java:1258)     在com.amazonaws.shade.http.AmazonHttpClient $ RequestExecutor.executeHelper(AmazonHttpClient.java:1030)     在com.amazonaws.shade.http.AmazonHttpClient $ RequestExecutor.doExecute(AmazonHttpClient.java:742)     在com.amazonaws.shade.http.AmazonHttpClient $ RequestExecutor.executeWithTimer(AmazonHttpClient.java:716)     在com.amazonaws.shade.http.AmazonHttpClient $ RequestExecutor.execute(AmazonHttpClient.java:699)     在com.amazonaws.shade.http.AmazonHttpClient $ RequestExecutor.access $ 500(AmazonHttpClient.java:667)     在com.amazonaws.shade.http.AmazonHttpClient $ RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)     在com.amazonaws.shade.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)     在com.amazonaws.shade.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3639)     在com.amazonaws.shade.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3586)     在com.amazonaws.shade.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1601)     在com.amazonaws.shade.services.s3.transfer.internal.UploadCallable.uploadInOneChunk(UploadCallable.java:133)     在com.amazonaws.shade.services.s3.transfer.internal.UploadCallable.call(UploadCallable.java:125)     在com.amazonaws.shade.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:143)     在com.amazonaws.shade.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:48)     at java.util.concurrent.FutureTask.run(FutureTask.java:266)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)

我的身份验证是这样的,其中token是从URL中提取的IAM令牌:

  String token = extractToken(path);


  propertiess = CH.updateToken(
      filesystemURI, conf, schemaProvided, token, props);
  serviceInstanceID = props.getProperty(IAM_SERVICE_INSTANCE_ID_PROPERTY);
  customToken = new CustomTokenManager(token);
  iamEndpoint = propertiess.getProperty(IAM_ENDPOINT_PROPERTY);
  SDKGlobalConfiguration.IAM_ENDPOINT = iamEndpoint;
  creds = new BasicOAuthCredentials(customToken, serviceInstanceID);

  clientConf = new ClientConfiguration();
  credProvider = new AWSStaticCredentialsProvider(creds);

  clientBuilder = AmazonS3ClientBuilder.standard()
      .withClientConfiguration(clientConf)
      .withPathStyleAccessEnabled(true)
      .withCredentials(credProvider);

  if (serviceUrl != null && !serviceUrl.equals(amazonDefaultEndpoint)) {

    EndpointConfiguration endpointConfiguration = new EndpointConfiguration(serviceUrl,
        Regions.DEFAULT_REGION.getName());
    clientBuilder.withEndpointConfiguration(endpointConfiguration);

  } else {

          clientBuilder.withRegion(Regions.DEFAULT_REGION);
  }

  mClient = clientBuilder.build();
}

有人知道为什么一个会成功而另一个会抛出403吗?据我所知,我的端点,存储桶,对象和令牌都是正确的。

更新: 经过进一步调查,实际上似乎是上传失败了:

    PutObjectRequest putObjectRequest = new PutObjectRequest(mBucket, objName, im, om);
    Upload upload = transfers.upload(putObjectRequest);
    upload.waitForUploadResult();

我从waitForUploadResult()获取错误。

此外,我正在尝试上传到Bluemix Cloud Object Stroage。

以下是service instance上的角色。

0 个答案:

没有答案