【问题标题】:Trying to listObjects from AWS S3 using anonymous credentials but it is still checking in ~/.aws/credentials尝试使用匿名凭证从 AWS S3 列出对象,但它仍在检查 ~/.aws/credentials
【发布时间】:2015-11-28 10:04:08
【问题描述】:

这是我用于listSummaries 对象的代码(与http://docs.aws.amazon.com/AmazonS3/latest/dev/ListingObjectKeysUsingJava.html 99% 相同)。

AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());  

    System.out.println("bucketname = " + bucketName + "key =" + key);


    ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(key);
    List<S3ObjectSummary> summaries = new ArrayList<S3ObjectSummary>();

    ObjectListing objectListing;

    do {
        line 147 >>> objectListing = s3client.listObjects(listObjectsRequest);
        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            summaries.add(objectSummary);
        }
        listObjectsRequest.setMarker(objectListing.getNextMarker());
    } while (objectListing.isTruncated());

这里说您可以使用匿名凭据访问可公开访问的存储桶 (http://docs.aws.amazon.com/AmazonS3/latest/dev/AuthUsingAcctOrUserCredJava.html) 我确信我正在访问的存储桶是开源的。我收到以下错误消息,但我不知道为什么会这样:

Exception in thread "main" java.lang.IllegalArgumentException: AWS credential profiles file not found in the given path: /home/xxx/.aws/credentials
at com.amazonaws.auth.profile.internal.ProfilesConfigFileLoader.loadProfiles(ProfilesConfigFileLoader.java:45)
at com.amazonaws.auth.profile.ProfilesConfigFile.loadProfiles(ProfilesConfigFile.java:194)
at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:119)
at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:93)
at com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials(ProfileCredentialsProvider.java:149)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3589)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3548)
at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:647)
at xxx.xxx.xxx.LocalInterface.ListBucket(LocalInterface.java:147)

【问题讨论】:

    标签: java amazon-web-services amazon-s3 aws-sdk


    【解决方案1】:

    我想出了自己的答案。我没有使用匿名凭据。以下是它们的使用方法:

    AWSCredentials creds = new AnonymousAWSCredentials();
        AmazonS3 s3client = new AmazonS3Client(creds);  
    

    希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 2017-02-10
      • 2019-02-23
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多