AWS error loading object from S3, "profile file cannot be empty"

I already saw this one , but there was no answer to explain my problem. At first I used the sample here (GetObject class), and it immediately worked on my desktop. However, my friend could not get him to work on his machine, and he would not work on our copy of EC2.

It was mentioned that credential files should be specified, which makes sense, but I never had to do this, and I'm sure that the default permissions were set to access this bucket.

Here's the stacktrace:

Exception in thread "main" java.lang.IllegalArgumentException: profile file cannot be null at com.amazonaws.util.ValidationUtils.assertNotNull(ValidationUtils.java:37) at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:142) at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:133) at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:100) at com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials(ProfileCredentialsProvider.java:135) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.getCredentialsFromContext(AmazonHttpClient.java:1029) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1049) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:949) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:662) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:636) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:619) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$300(AmazonHttpClient.java:587) at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:574) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:446) at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4035) at com.amazonaws.services.s3.AmazonS3Client.getBucketRegionViaHeadRequest(AmazonS3Client.java:4474) at com.amazonaws.services.s3.AmazonS3Client.fetchRegionFromCache(AmazonS3Client.java:4448) at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4020) at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:1307) at GetObject.main(GetObject.java:26) 

I can guarantee that neither the bucketName nor the key parameters in GetObjectRequest are non-zero. What is the discrepancy here? Why can this only happen on my PC? Is this generally due to the fact that I had to supplement the numerous banks that were supposed to have an aws-sdk jar (jackson-fraction, jackson-core, jackson-annotations, httpclient, httpcore, commons-logging and joda- time)? It seems that with unexplained errors (giving non-empty parameters, something in aws-sdk says it's empty).

+3
java amazon-s3 amazon-web-services amazon-ec2
source share
1 answer

It looks like you solved it in the comments, but I was burned on this and want to leave a clearer answer to future readers. To be very clear, the problem here has nothing to do with files in S3. This error message has nothing to do with the file on your hard drive or the file that you are trying to push / pull from S3. The problem is that you initialize S3 with something like:

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

When you do this, it looks in ~ / .aws / credentials for a list of profiles. This may work fine on your computer, but will not work anywhere when you access AWS through the IAM role (e.g. Lambda, Docker, EC2, etc.). Bugfix: initialize AmazonS3Client as follows:

 AmazonS3 s3Client = new AmazonS3Client(); 

If you use code that requires a credential provider, you can also:

 AmazonS3 s3Client = new AmazonS3Client(DefaultAWSCredentialsProviderChain.getInstance()); 

Hope this helps the next person. In my case, I used DynamoDB and SQS, but I had the same error. I initially ignored this question because I thought your problem with S3 was confused. Wrist slap.

+10
source share

All Articles