Java 尝试使用匿名凭据从AWS S3列出对象,但它仍在签入~/.AWS/credentials

Java 尝试使用匿名凭据从AWS S3列出对象,但它仍在签入~/.AWS/credentials,java,amazon-web-services,amazon-s3,aws-sdk,Java,Amazon Web Services,Amazon S3,Aws Sdk,下面是我用来列出对象摘要的代码(99%与源代码相同) AmazonS3 s3client=新的AmazonS3客户端(新的ProfileCredentialsProvider()); System.out.println(“bucketname=“+bucketname+”key=“+key”); ListObjectsRequest ListObjectsRequest=新建ListObjectsRequest()。带bucketName(bucketName)。带前缀(键); 列表摘要=新的

下面是我用来
列出对象摘要的代码(99%与源代码相同)

AmazonS3 s3client=新的AmazonS3客户端(新的ProfileCredentialsProvider());
System.out.println(“bucketname=“+bucketname+”key=“+key”);
ListObjectsRequest ListObjectsRequest=新建ListObjectsRequest()。带bucketName(bucketName)。带前缀(键);
列表摘要=新的ArrayList();
对象列表对象列表;
做{
第147行>>>objectListing=s3client.listObjects(listObjectsRequest);
对于(S3ObjectSummary objectSummary:objectListing.getObjectSummaries()){
摘要。添加(objectSummary);
}
listObjectsRequest.setMarker(objectListing.getNextMarker());
}while(objectListing.isTruncated());
在这里,它说您可以使用匿名凭据访问可公开访问的bucket(),我确信我正在访问的bucket是开源的。我收到以下错误消息,我不知道为什么会发生这种情况:

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)
线程“main”java.lang.IllegalArgumentException中的异常:在给定路径中未找到AWS凭据配置文件:/home/xxx/.AWS/credentials 在com.amazonaws.auth.profile.internal.ProfilesConfigFileLoader.loadProfiles(ProfilesConfigFileLoader.java:45) 在com.amazonaws.auth.profile.ProfilesConfigFile.loadProfiles(ProfilesConfigFile.java:194) 位于com.amazonaws.auth.profile.ProfilesConfigFile.(ProfilesConfigFile.java:119) 位于com.amazonaws.auth.profile.ProfilesConfigFile.(ProfilesConfigFile.java:93) 在com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials上(ProfileCredentialsProvider.java:149) 位于com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3589) 位于com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3548) 位于com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:647) 位于xxx.xxx.xxx.LocalInterface.ListBucket(LocalInterface.java:147)
我想出了自己的答案。我没有使用匿名凭证。以下是如何使用它们:

AWSCredentials creds = new AnonymousAWSCredentials();
    AmazonS3 s3client = new AmazonS3Client(creds);  
希望这对别人有帮助

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