运行
$ aws s3 ls s3://mybucket/myfolder/subfolder/monitor/
它将返回我期望的所有文件。我正确设置了权限和凭据。然后我写了一些java代码:
public class S3Sample {
public static void main(String[] args) throws IOException {
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider().getCredentials();
} catch (Exception e) {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
AmazonS3 s3 = new AmazonS3Client(credentials);
try {
ObjectListing objectListing = s3.listObjects(new ListObjectsRequest()
.withBucketName("mybucket"));
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
System.out.println(objectSummary.getKey());
}
} 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 S3, "
+ "such as not being able to access the network.");
System.out.println("Error Message: " + ace.getMessage());
}
}
代码在mybucket / myfolder /子文件夹中打印出来,但是在监视器中没有任何内容(并且缺少其他子目录)。我没有看到任何错误。如何诊断为什么我没有看到更多的文件。我明显拥有文件夹和凭据的权限。任何建议都有帮助。谢谢!